0

I tried to solve by myself but couldn't after spending so much of time and finally came here. I just want to add user's input into database but my create() method keeps getting NullPointerException. please tell me why it does and what i should do with my code. getter and setter are left out. Thanks.

Bb.java

@Named
@SessionScoped
public class Bb implements Serializable {

private Long id;
@NotNull
private String firstName;
@NotNull
private String lastName;
@NotNull
private String firstNameHurigana;
@NotNull
private String lastNameHurigana;
@NotNull
private String addressOne;
@NotNull
private String addressTwo;
@NotNull
private String birthYear;
@NotNull
private String birthMonth;
@NotNull
private String birthDay;
@NotNull
private String firstNameWife;
@NotNull
private String lastNameWife;
@NotNull
private String firstNameHuriganaWife;
@NotNull
private String lastNameHuriganaWife;
@NotNull
private String birthYearWife;
@NotNull
private String birthMonthWife;
@NotNull
private String birthDayWife;
@NotNull
private String housePhoneNumberOne;
@NotNull
private String housePhoneNumberTwo;
@NotNull
private String housePhoneNumberThree;
private String housePhoneNumber = housePhoneNumberOne + housePhoneNumberTwo + housePhoneNumberThree;
@NotNull
private String mobilePhoneNumberOne;
@NotNull
private String mobilePhoneNumberTwo;
@NotNull
private String mobilePhoneNumberThree;
private String mobilePhoneNumber = mobilePhoneNumberOne + mobilePhoneNumberTwo + mobilePhoneNumberThree;
@NotNull
private String mailAddress;




@Inject
transient Logger log;


public String goToInput() {
    System.out.println("back to input.");
    return "input.xhtml";
}

public String goToConfirm() {
    System.out.println("move to confirm page.");
    return "confirm.xhtml";
}

public String goToComplete() {
    OldCoupleInformationDb db = new OldCoupleInformationDb();

    OldCoupleInformation oci = new OldCoupleInformation(firstName, lastName,
            firstNameHurigana, lastNameHurigana, addressOne, addressTwo, birthYear,
            birthMonth, birthDay, firstNameWife, lastNameWife, firstNameHuriganaWife,
            lastNameHuriganaWife, birthYearWife, birthMonthWife, birthDayWife, housePhoneNumberOne,
            housePhoneNumberTwo, housePhoneNumberThree, mobilePhoneNumberOne, mobilePhoneNumberTwo,
            mobilePhoneNumberThree, mailAddress);
    System.out.println("move to complete page.");
    System.out.println(oci.toString());
    db.create(oci);
    return "complete.xhtml";
}
//create() was here

public void create(OldCoupleInformation oci) {
    OldCoupleInformationDb db = new OldCoupleInformationDb();

    try {
        System.out.println("#########################################################");
        System.out.println("ok1");
        db.create(oci);
        clear();
    } catch (Exception e) {
        System.out.println("miss");
        log.severe("新規登録できない/" + firstName);
    } finally {

    }
}

public void clear() {
    firstName = lastName
            = firstNameHurigana = lastNameHurigana = addressOne = addressTwo = birthYear
            = birthMonth = birthDay = firstNameWife = lastNameWife = firstNameHuriganaWife
            = lastNameHuriganaWife = birthYearWife = birthMonthWife = birthDayWife = housePhoneNumberOne
            = housePhoneNumberTwo = housePhoneNumberThree = mobilePhoneNumberOne = mobilePhoneNumberTwo
            = mobilePhoneNumberThree = mailAddress = null;
}

OldCoupleInformation.java

@Entity

@Table(name = "KAGUYA") public class OldCoupleInformation implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
private String firstName;
@NotNull
private String lastName;
@NotNull
private String firstNameHurigana;
@NotNull
private String lastNameHurigana;
@NotNull
private String addressOne;
@NotNull
private String addressTwo;
@NotNull
private String birthYear;
@NotNull
private String birthMonth;
@NotNull
private String birthDay;
@NotNull
private String firstNameWife;
@NotNull
private String lastNameWife;
@NotNull
private String firstNameHuriganaWife;
@NotNull
private String lastNameHuriganaWife;
@NotNull
private String birthYearWife;
@NotNull
private String birthMonthWife;
@NotNull
private String birthDayWife;

@NotNull
private String housePhoneNumberOne;
@NotNull
private String housePhoneNumberTwo;
@NotNull
private String housePhoneNumberThree;
private String housePhoneNumber = housePhoneNumberOne + housePhoneNumberTwo + housePhoneNumberThree;
@NotNull
private String mobilePhoneNumberOne;
@NotNull
private String mobilePhoneNumberTwo;
@NotNull
private String mobilePhoneNumberThree;
private String mobilePhoneNumber = mobilePhoneNumberOne + mobilePhoneNumberTwo + mobilePhoneNumberThree;
@NotNull
private String mailAddress;




public OldCoupleInformation(String firstName, String lastName, String firstNameHurigana, String lastNameHurigana, String addressOne, String addressTwo, String birthYear, String birthMonth, String birthDay, String firstNameWife, String lastNameWife, String firstNameHuriganaWife, String lastNameHuriganaWife, String birthYearWife, String birthMonthWife, String birthDayWife, String housePhoneNumberOne, String housePhoneNumberTwo, String housePhoneNumberThree, String mobilePhoneNumberOne, String mobilePhoneNumberTwo, String mobilePhoneNumberThree, String mailAddress) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.firstNameHurigana = firstNameHurigana;
    this.lastNameHurigana = lastNameHurigana;
    this.addressOne = addressOne;
    this.addressTwo = addressTwo;
    this.birthYear = birthYear;
    this.birthMonth = birthMonth;
    this.birthDay = birthDay;
    this.firstNameWife = firstNameWife;
    this.lastNameWife = lastNameWife;
    this.firstNameHuriganaWife = firstNameHuriganaWife;
    this.lastNameHuriganaWife = lastNameHuriganaWife;
    this.birthYearWife = birthYearWife;
    this.birthMonthWife = birthMonthWife;
    this.birthDayWife = birthDayWife;
    this.housePhoneNumberOne = housePhoneNumberOne;
    this.housePhoneNumberTwo = housePhoneNumberTwo;
    this.housePhoneNumberThree = housePhoneNumberThree;
    this.mobilePhoneNumberOne = mobilePhoneNumberOne;
    this.mobilePhoneNumberTwo = mobilePhoneNumberTwo;
    this.mobilePhoneNumberThree = mobilePhoneNumberThree;
    this.mailAddress = mailAddress;
}

public OldCoupleInformation() {
}

OldCoupleInformationDb

@Stateless

public class OldCoupleInformationDb {

@PersistenceContext
private EntityManager em;

public void create(OldCoupleInformation oldCoupleInformation) {
    System.out.println(em);
    System.out.println("########################################################################");
    em.persist(oldCoupleInformation);

}

}

Error

javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException at com.sun.common.util.logging.LoggingOutputStream$LoggingPrintStream.println(LoggingOutputStream.java:228) at org.apache.felix.gogo.runtime.threadio.ThreadPrintStream.println(ThreadPrintStream.java:205) at Db.OldCoupleInformationDb.create(OldCoupleInformationDb.java:25) at Db.Bb.create(Bb.java:126) at Db.Bb.goToComplete(Bb.java:102) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at javax.el.ELUtil.invokeMethod(ELUtil.java:332) at javax.el.BeanELResolver.invoke(BeanELResolver.java:537) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256) at com.sun.el.parser.AstValue.invoke(AstValue.java:283) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 36 more

anonyrabbit
  • 87
  • 1
  • 9
  • where do you get the NPE ? Is it the EM that is null ? – Cédric O. Oct 26 '16 at 11:40
  • 1
    Start by reading http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it And how is this JSF related? Do you not get the value from the client? Then it is jsf related. If not, it is JPA related – Kukeltje Oct 26 '16 at 12:43

1 Answers1

0

It looks like your create() method definition does not take any parameters and yet you have a argument in the create(oci) when you use it. Try using the create() without the argument oci.