NullPointerException on object methods

Hello everybody! I just started learning Java yesterday, and am looking forward to contributing to the forum!
Here is a code I was working on today- it's the start of a simple game of blackjack.
import java.util.Scanner;
class BlackJack {
     public static void main(String[] args) {
          Deck deck = new Deck();
          System.out.print("Enter your name > ");
          Scanner in = new Scanner(System.in);
          String name = in.nextLine();
          Hand phand = new Hand(name);
          phand.addCards(2,deck);
          Hand dhand = new Hand("Dealer");
          dhand.addCards(2,deck);
          System.out.println("Dealer: "+dhand.readHand(true));
          System.out.println("You:    "+phand.readHand());
          System.out.println(phand.sum);
}Then here is the Deck class:
import java.util.Random;
public class Deck {
     private int[] cards;
     public int getCard() {
          Random generator=new Random();
          int randomInt, out;
          do {randomInt=generator.nextInt(52);}
          while (cards[randomInt]==0);
          out=cards[randomInt];
          cards[randomInt]=0;
          return out;
     public void shuffle() {
          int[] newCards={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
          cards=newCards;
     public Deck() {
          int[] cards = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
}And here is the Hand class:
public class Hand {
     private int[] cards;
     private int sum;
     public String name;
     public void addCards(int numCards, Deck deck) {
          for (int i=0;i<numCards;i++) {
               int newCard=deck.getCard();
               cards[cards.length]=newCard;
               sum+=newCard;
     public int getSum() {
          return sum;
     public String readHand(boolean isHidden) {
          String out="";
          if (isHidden) {
               out=cards[0]+" x";
          else {
               for (int i=0;i<cards.length;i++) {
                    out+=cards[i]+" ";
          return out;
     public String readHand() {
          return readHand(false);
     public Hand(String newName) {
          cards=new int[10];
          sum=0;
          name=newName;
}Now I'm getting this runtime error:
Exception in thread "main" java.lang.NullPointerException
        at Deck.getCard(Deck.java:8)
        at Hand.addCards(Hand.java:7)
        at BlackJack.main(BlackJack.java:9)I found online that the NullPointerException means that the object I'm calling is null, but I can't figure out why. I assume it's a simple thing that I overlooked (or haven't learned yet), but the curious thing is when I commented out the lines which caused the exception, and made the sum from the hand class public, I could use it fine. Any help is greatly appreciated!
-seveneightn9ne

Now compiling Deck results in these errors:
Deck.java:7: cannot find symbol
symbol  : variable cards
location: class Deck
        cards = new int[] {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10};
        ^
Deck.java:13: cannot find symbol
symbol  : variable cards
location: class Deck
                while (cards[randomInt]==0);
                       ^
Deck.java:14: cannot find symbol
symbol  : variable cards
location: class Deck
                out=cards[randomInt];
                    ^
Deck.java:15: cannot find symbol
symbol  : variable cards
location: class Deck
                cards[randomInt]=0;
                ^
Deck.java:20: cannot find symbol
symbol  : variable cards
location: class Deck
                cards=newCards;
                ^
5 errorsHere is what Deck currently looks like:
import java.util.Random;
public class Deck {
     public Deck() {
     cards = new int[] {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
     public int getCard() {
          Random generator=new Random();
          int randomInt, out;
          do {randomInt=generator.nextInt(52);}
          while (cards[randomInt]==0);
          out=cards[randomInt];
          cards[randomInt]=0;
          return out;
     public void shuffle() {
          int[] newCards={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
          cards=newCards;
}Is it correct that cards is not declared outside the constructor, or is that the cause of the error?

Similar Messages

  • Want to know how to debug the Business Object Method called from CRM

    Hi all,
    I have to debug a Method of a custom Business Object. This is being called when a certain action is performed
    on the CRM  ( CIC0 screen). I can not see an option to set an external break point in the Program of the Business Object
    Method.
    This Business Object calls a standard SAP FM. I tried setting an external break point in that FM and tried executing that.
    But it  is not stopping there.
    Can any one please let me know how I can debug this when triggered from CRM?
    Thanks  in advance.
    Thanks & regards,
    Y Gautham

    Hi,
    I have tried checking the option 'IP MATCHING' option. I have given my user id and also the 'WEBUSER' as well.
    But still I am unable to debug the application.
    Can you please let me know if I am missing anything further.
    Thanks & regards,
    Y Gautham

  • HOWTO: Expose Entity Object Methods to Clients

    By design, clients cannot directly access entity objects. The view object layer provides an extra layer of security--you can choose exactly what data and methods you want clients to see.
    This HOWTO describes the process of exposing an entity object method to client programs.
    First, if you don't already have one, you must base a view object on your entity object and add the view object to your data model. For full details of how to do this, see the help topics under
    +Developing Business Components
    --Working with View Objects, View Links, Application Modules, and Clients
    +----Creating and Modifying View Objects, View Links, Application Modules, and Clients
    For the purposes of this HOWTO, we'll assume that you already have an entity object, Employees, with a method on it, calculateBonus(),
    and a view object EmployeesView based on Employees.
    First, you must generate a view row class. A view row represents one row of the view object's cache; it corresponds to a view of a particular entity object.
    To generate a view row class:
    1. Right-click EmployeesView and choose Edit.
    2. In the View Object Editor, select the Java page.
    3. Select Generate Java File and Generate Accessors for the view row class.
    4. Click Done. This creates a class called EmployeesViewRowImpl.
    Next, you should add a "delegator" method to the view row class--a public method with the exact same signature as the entity method, that simply calls the entity method. For example:
    public int calculateBonus(int rating) {
    return getEmployees().calculateBonus(rating);
    Next, you should export this method.
    1. Right-click EmployeesView and choose Edit.
    2. In the View Object Editor, select the Client Row Methods page.
    3. Shuttle the method you just created into the Selected list and click Done.
    This creates an interface called EmployeesViewRow that contains your method.
    Now you can call the method from your client. You should cast the row returned by EmployeesView.current(), the <jbo:Row> tag, or a similar method or data tag to EmployeesViewRow.
    For example,
    <jbo:Row id="myRow" datasource="ds" action=Current>
    <% out.println(((EmployeesViewRow) myRow).calculateBonus(3)); %>
    </jbo:Row>
    null

    Hi Lisa,
    There's a difference between exporting methods (on an application module, view object, and view row--this is done on the "Client Methods" tab of the view object and application module wizards and the "Client Row Methods" tab of the view object wizard) and making an application module remotable (which is done on the "remote" tab of the application module wizard).
    You should always export methods you want clients to use--and you only need to do this on the application module if you've written methods on your application module (which I didn't in this HOWTO). You can still use these methods in local mode--the interfaces will be present locally. The advantage of exporting methods is that it doesn't lock you into local mode--you'll be able to change to remote mode later (if you decide that's the way to go) with minimal changes--because the interfaces will be present locally even when the implementation classes aren't.
    By contrast, you should only make an application module remotable if you're planning on deploying in a non-local configuration. You can do this step right before deployment.
    Hope this helps,
    Avrom
    null

  • How to manage optional output parameters in an object method ?

    Hi Abapers,
    I've a little coding point to clarify in object programming :
    I've defined an output method parameter as optional.
    I want to prevent execution error with the following test :
    IF et_my_ouput_paramer IS REQUESTED.
       APPEND LINES OF lt_my_data_found TO et_my_ouput_paramer . "*(or other value affectation, no matter)
    ENDIF.
    When activating the code, I obtain the following error :
    "IS REQUESTED" is allowed only with function parameters. This means
    that it is allowed only within the relevant function module and not
    with pure incoming parameters.
    Effectively, I usely use "IS REQUESTED" for module-function... What's the correct syntax in object method ?
    Thanks in advance.

    OK, guys, it was a very tricky and basic error...
    Sorry for this topic, I mistake in declaring type of my parameters.
    Keep programming Quietly !
    Have a nice day.

  • Why is String method called not Object method

    In the below program ::
    class Test
         public void callMethod(Object o)
              System.out.println("Object Method Called");
         public void callMethod(String s)
              System.out.println("String Method Called");
         public static void main(String[] args)
              Test t = new Test();
              t.callMethod(null);
    }

    In the below program ::
    class Test
         public void callMethod(Object o)
              System.out.println("Object Method Called");
         public void callMethod(String s)
              System.out.println("String Method Called");
         public static void main(String[] args)
              Test t = new Test();
              t.callMethod(null);
    }If more than one method could be called the most specific one is called. Since a String is an Object then the String one gets called.

  • Connect to COM(OBJECTS/METHODS) FROM ABAP

    Dear all.
    How can I connect to COM objects/methods from abap?
    Could give me link to example.

    Yes this method raises and exception with this message
    Message ID:          FDT_CORE
    Message number:      085
    DO_IM_DATETIME is not in the context
    The method SET_VALUE corresponds to IF_FDT_CONTEXT. This is the method's calls
          lv_name = 'DO_IM_DATETIME'.
          TRY.
              o_context->set_value( iv_name =  lv_name
                                    ia_value = lv_element_tzone ).
            CATCH cx_fdt INTO lx_fdt.
              RAISE incorrect_parameter.
          ENDTRY.
    I reactivate the aplication, the function, the expression and the data objects.
    But the method is still giving this exception.
    I have only this exception when I try to set up this two parameters:
    DO_IM_DATETIM of type Timepoint
    DO_IM_LANGU which is binding to the element type LANGU
    But in my BRFPlus Function Context I do have this two parameters.
    Thanks !

  • Access an objects method + no line terminator

    Hi,
    I've just found out that if you can use the objects methods by not terminating a line with semicolon;
    StringBuffer sb = new StringBuffer();
    sb.append("A")
        .append("B")
        .append("C");Is this because the terminator closes access to the object and its methods, so not placing a terminator allows a VB style with statement to just access the methods.
    Why/How is this possible?
    Is it good practice?
    Any Help on this would be great,
    Cheers

    It's because the append() method returns an instance of itself. I.e. it's implemented like this:
    public StringBuffer append(String text) {
       // ... do internal operations to add the string
       return this;
    }The semi-colon ends the statement. Since you haven't closed the statement, you have access to the l-value (the returned value from the method) and can invoke methods on the object that it references.
    Is it good practice?It's sometimes useful, but it can be overused.

  • Help required: Using objects/methods in other classes

    Hi
    Say you have a class that has a private string instance variable and you have a accessor and mutator method for this object in that class.
    You have another class that needs to access this object via the accessor and mutator methods. How do you do this? When I try I only get nullPointerExceptions or Stack Overflows!!! If anyone can provide some code on how to do this successfully then that will be most appreciated. Thanks.

    Kayaman gave you the right answer
    public class MyDataClass {
    private String importantString;
    public void setImpString(String s) {
    importantString = s;
    public String getImpString() {
    return importantString;
    public class MyMainClass {
    public static void main(String[] args) {
    MyDataClass a = new MyDataClass();
    a.setImpString("This is important");
    System.out.println(a.getImpString());
    }Note that he sets the value of the imp string before trying to get it. The nullpointer that you say is probably because you dont do that.
    Also When you aks a question a little humility doesnt hurt.
    You do need a tutorial first.

  • NullPointerException in persist() method

    Hi,
    I'm new using JPA (TopLinks) and have the following problem:
    In a managed bean that uses resource injection, i.e
    +@PersistentContext+
    private EntityManager em;
    when calling em.persist(object) always get a java.lang.NullPointerException, no matter what entity trying to persist.
    Somebody can help ?
    Thanks in advance
    edu

    Here is the server log :
    06/11/2007 11:59:53 com.sun.enterprise.admin.servermgmt.launch.ASLauncher buildCommand
    INFO:
    D:/Program Files/Java/jdk1.6.0_02\bin\java
    -Dcom.sun.aas.instanceRoot=D:/Program Files/glassfish-v2-b58g/domains/domain1
    -Dcom.sun.aas.ClassPathPrefix=
    -Dcom.sun.aas.ClassPathSuffix=
    -Dcom.sun.aas.ServerClassPath=
    -Dcom.sun.aas.classloader.appserverChainJars.ee=
    -Dcom.sun.aas.classloader.appserverChainJars=admin-cli.jar,admin-cli-ee.jar,j2ee-svc.jar
    -Dcom.sun.aas.classloader.excludesList=admin-cli.jar,appserv-upgrade.jar,sun-appserv-ant.jar
    -Dcom.sun.aas.classloader.optionalOverrideableChain.ee=
    -Dcom.sun.aas.classloader.optionalOverrideableChain=webservices-rt.jar,webservices-tools.jar
    -Dcom.sun.aas.classloader.serverClassPath.ee=/lib/hadbjdbc4.jar,D:/Program Files/glassfish-v2-b58g/lib/SUNWjdmk/5.1/lib/jdmkrt.jar,/lib/dbstate.jar,/lib/hadbm.jar,/lib/hadbmgt.jar,D:/Program Files/glassfish-v2-b58g/lib/SUNWmfwk/lib/mfwk_instrum_tk.jar
    -Dcom.sun.aas.classloader.serverClassPath=D:/Program Files/glassfish-v2-b58g/lib/install/applications/jmsra/imqjmsra.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/jaxm-api.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/fscontext.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/imqbroker.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/imqjmx.jar,D:/Program Files/glassfish-v2-b58g/lib/ant/lib/ant.jar,D:/Program Files/glassfish-v2-b58g/lib/SUNWjdmk/5.1/lib/jdmkrt.jar
    -Dcom.sun.aas.classloader.sharedChainJars.ee=appserv-se.jar,appserv-ee.jar,jesmf-plugin.jar,/lib/dbstate.jar,/lib/hadbjdbc4.jar,jgroups-all.jar,D:/Program Files/glassfish-v2-b58g/lib/SUNWmfwk/lib/mfwk_instrum_tk.jar
    -Dcom.sun.aas.classloader.sharedChainJars=javaee.jar,D:/Program Files/Java/jdk1.6.0_02/lib/tools.jar,install/applications/jmsra/imqjmsra.jar,com-sun-commons-launcher.jar,com-sun-commons-logging.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/jaxm-api.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/fscontext.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/imqbroker.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/imqjmx.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/imqxm.jar,webservices-rt.jar,webservices-tools.jar,mail.jar,appserv-jstl.jar,jmxremote_optional.jar,D:/Program Files/glassfish-v2-b58g/lib/SUNWjdmk/5.1/lib/jdmkrt.jar,activation.jar,appserv-rt.jar,appserv-admin.jar,appserv-cmp.jar,D:/Program Files/glassfish-v2-b58g/updatecenter/lib/updatecenter.jar,D:/Program Files/glassfish-v2-b58g/jbi/lib/jbi.jar,D:/Program Files/glassfish-v2-b58g/imq/lib/imqjmx.jar,D:/Program Files/glassfish-v2-b58g/lib/ant/lib/ant.jar,dbschema.jar
    -Dcom.sun.aas.configName=server-config
    -Dcom.sun.aas.configRoot=D:/Program Files/glassfish-v2-b58g/config
    -Dcom.sun.aas.defaultLogFile=D:/Program Files/glassfish-v2-b58g/domains/domain1/logs/server.log
    -Dcom.sun.aas.domainName=domain1
    -Dcom.sun.aas.installRoot=D:/Program Files/glassfish-v2-b58g
    -Dcom.sun.aas.instanceName=server
    -Dcom.sun.aas.processLauncher=SE
    -Dcom.sun.aas.promptForIdentity=true
    -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory
    -Dcom.sun.enterprise.overrideablejavaxpackages=javax.help,javax.portlet
    -Dcom.sun.enterprise.taglibs=appserv-jstl.jar,jsf-impl.jar
    -Dcom.sun.enterprise.taglisteners=jsf-impl.jar
    -Dcom.sun.updatecenter.home=D:/Program Files/glassfish-v2-b58g/updatecenter
    -Ddomain.name=domain1
    -Djava.endorsed.dirs=D:/Program Files/glassfish-v2-b58g/lib/endorsed
    -Djava.ext.dirs=D:/Program Files/Java/jdk1.6.0_02/lib/ext;D:/Program Files/Java/jdk1.6.0_02/jre/lib/ext;D:/Program Files/glassfish-v2-b58g/domains/domain1/lib/ext;D:/Program Files/glassfish-v2-b58g/javadb/lib
    -Djava.library.path=D:\Program Files\glassfish-v2-b58g\lib;D:\Program Files\glassfish-v2-b58g\lib;D:\Program Files\glassfish-v2-b58g\bin;D:\Program Files\glassfish-v2-b58g\lib
    -Djava.security.auth.login.config=D:/Program Files/glassfish-v2-b58g/domains/domain1/config/login.conf
    -Djava.security.policy=D:/Program Files/glassfish-v2-b58g/domains/domain1/config/server.policy
    -Djava.util.logging.manager=com.sun.enterprise.server.logging.ServerLogManager
    -Djavax.management.builder.initial=com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder
    -Djavax.net.ssl.keyStore=D:/Program Files/glassfish-v2-b58g/domains/domain1/config/keystore.jks
    -Djavax.net.ssl.trustStore=D:/Program Files/glassfish-v2-b58g/domains/domain1/config/cacerts.jks
    -Djdbc.drivers=org.apache.derby.jdbc.ClientDriver
    -Djmx.invoke.getters=true
    -Dsun.rmi.dgc.client.gcInterval=3600000
    -Dsun.rmi.dgc.server.gcInterval=3600000
    -client
    -XX:+UnlockDiagnosticVMOptions
    -XX:MaxPermSize=192m
    -Xmx512m
    -XX:NewRatio=2
    -XX:+LogVMOutput
    -XX:LogFile=D:/Program Files/glassfish-v2-b58g/domains/domain1/logs/jvm.log
    -cp
    D:/Program Files/glassfish-v2-b58g/lib/jhall.jar;D:\Program Files\glassfish-v2-b58g\lib\appserv-launch.jar
    com.sun.enterprise.server.PELaunch
    start
    Starting Sun Java System Application Server 9.1 (build b58g-fcs) ...
    MBeanServer started: com.sun.enterprise.interceptor.DynamicInterceptor
    CORE5098: AS Socket Service Initialization has been completed.
    CORE5076: Using [Java HotSpot(TM) Client VM, Version 1.6.0_02] from [Sun Microsystems Inc.]
    SEC1002: Security Manager is OFF.
    D:/Program Files/glassfish-v2-b58g/domains/domain1/config/.__com_sun_appserv_pid
    ADM0001:SunoneInterceptor is now enabled
    SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
    WEB0114: SSO is disabled in virtual server [server]
    WEB0114: SSO is disabled in virtual server [__asadmin]
    ADM1079: Initialization of AMX MBeans started
    ADM1504: Here is the JMXServiceURL for the Standard JMXConnectorServer: [service:jmx:rmi:///jndi/rmi://t0002038990.telecom.arg.telecom.com.ar:8686/jmxrmi]. This is where the remote administrative clients should connect using the standard JMX connectors
    ADM1506: Status of Standard JMX Connector: Active = [true]
    WEB0302: Starting Sun-Java-System/Application-Server.
    JBIFW0010: JBI framework ready to accept requests.
    WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 8080
    WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 8181
    WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 4848
    naming.bind
    Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03) for context '/BizChallenge'
    SMGT0007: Self Management Rules service is enabled
    Application server startup complete.
    deployed with moduleid = BizChallenge
    naming.bind
    Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03) for context '/BizChallenge'
    java.lang.NullPointerException
    javax.faces.el.EvaluationException: java.lang.NullPointerException
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
    at com.sun.rave.web.ui.appbase.faces.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
    at javax.faces.component.UICommand.broadcast(UICommand.java:383)
    at com.sun.webui.jsf.component.WebuiCommand.broadcast(WebuiCommand.java:160)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.execute(PartialTraversalLifecycle.java:94)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
    at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:267)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
    Caused by: java.lang.NullPointerException
    at bizchallenge.FormAdmin.persist(FormAdmin.java:32)
    at bizchallenge.FormAdmin.saveLoanForm(FormAdmin.java:38)
    at bizchallenge.BankLoan.btnEnviar_action(BankLoan.java:379)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
    ... 45 more

  • Using null for parameterized "newInstance(Object [])" method in Object[].

    I have a really serious problem. I am creating instances of specific classes by using reflection techniques. I am reading a flat file, finding class from its name and creating it by using its parameterized constructor. Example:
    line 1: Dummy("A",Dummy2("B"),12,,"C");
    I create an instance of Dummy with parameters "A", an instance of Dummy2 object with value "B", 12 (I use here Integer as wrapper), null (There is no wrapper for null :( ) and "C".
    I find constructor by using findConstructors() and looking their parameter counts, creating an object array with given values and calling:
    constructorIFoundBefore.newInstance(objectArrayIPrepared);
    But!!!
    Because I use null directly, I got this message:
    java.lang.IllegalArgumentException: argument type mismatch
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
         at reader.parser.ObjectCreator.createObjectFromObjectItem(ObjectCreator.java:192)
         at reader.parser.ObjectCreator.createObjectFromParseItem(ObjectCreator.java:112)
         at reader.parser.ObjectCreator.createObject(ObjectCreator.java:78)
         at reader.analyzer.FileAnalyzer.analyzeAndCreateObjects(FileAnalyzer.java:95)
         at reader.ReverseReader.main(ReverseReader.java:43)
    I will be very glad if you help me.
    Thanks a lot!
    Gokcer

    I said something wrong. Sorry. While invoking a method (or a constructor) we need an object array which are equivalent to parameters. For example to call a method or constructor for class A;
    class A {
    int age;
    String name;
    public A(int age, String name){
    this.age = age;
    this.name = name;
    public set(int age, String name){
    this.age = age;
    this.name = name;
    we use in any place
    A a1 = new A(12,"Gokcer");
    A a2 = new A(15,null);
    To achieve this by using reflection techniques, we must find constructor with two parameters of class A. At this point "BetterMethodFinder" will give great help.
    After finding right constructor, we must create an object array to tell the constructor parameters (age and name). At this point we need an object array which stores our parameters. Code must be like this.
    Object []params = new Object[2]; // we have two parameters.
    params[0] = new Integer(12); // we can't use params[0]=12
    // because 12 is not an object. (It is a
    // primitive type)
    params[1] = "Gokcer";
    Now create the new object.
    A a1;
    a1 = constructorWeFound.newInstance(params);
    While creating param[], we could also use:
    Object []params = new Object[2] {new Integer(12),"Gokcer"};
    While creating a2, we can use "null" directly for second parameter.
    params = new Object[2] = {new Integer(15), null};
    or
    Object []params = new Object[2];
    params[0] = new Integer(15);params[1] = null;
    Thanks again everyone who replied me.
    My sincerely...

  • Business Object Method is not Visible

    Hi Experts,
    I have created a custom business object and created a method for it in t-code SWO1.
    I am trying to use this object's method in one of workflow tasks. I entered the business object and I do not find the method in the method's list.
    I released the business object, still I do not find the method in pull up menu. Am I missing anything?
    Thanks!
    Babu.

    Hi Babu,
    Is this question being answered. If YES then please marked this question as answered.
    I do have some other solution. Hope this will work.
    Well, if you are trying to directly use the method of the Custom BOR in any of the custom task, then check whether the method have been marked as Instance independent?
    Double click in the method.
    Check the box and tick it for the Method to be instance independent.
    Generate it once again and check...
    Reward points if found useful.
    Regards.
    Abhijit.
    [email protected]

  • How to call object method (eg, CallIntMethod)in C?

    I aslo get problem when I use "CallIntMehtod", the following is my program
    test.java
    public class test {
    public int getvalue(int n)
    System.out.println("cjf, welcome");
    return n*n;
    invoke.c
    #include <jni.h>
    int main() {
    int res;
    JavaVM *jvm;
    JNIEnv *env;
    JavaVMInitArgs vm_args;
    JavaVMOption options[3];
    jclass cls;
    jmethodID mid;
    vm_args.version = JNI_VERSION_1_2;
    vm_args.nOptions = 3;
    // vm_args.options = options;
    vm_args.ignoreUnrecognized = JNI_TRUE;
    res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); /* create VM */
    if (res < 0) {
    fprintf(stderr, "Can't create Java VM\n");
    exit(1);
    printf("success create java VM \n");
    cls = (*env)->FindClass(env, "test");/* find class */
    if ( cls != (jclass)0 ) {
    mid = (*env)->GetMethodID( env, cls, "getvalue", "(I)I" );/* get method ID */
    if( mid != 0 ){
    printf("First call to Java returns:%d\n", (*env)->CallIntMethod(env, cls, mid,2) );/* execute
    method */
    (*jvm)->DestroyJavaVM(jvm);/* destroy java VM */
    fprintf(stdout, "Java VM destory.\n");
    return 0;
    when I compiled them and run it, I cann't get the expected result. the result is:
    nspws1@/home/bss>./invoke
    success create java VM
    First call to Java returns:0
    Java VM destory.
    so ,what' wrong?

    Your method "getvalue" is not static.
    You have to create an object of your class "test" and call the method with this object (not with the class) as parameter: CallIntMethod(env, obj, mid,2).

  • Java.lang.NullPointerException in checkTransaction method

    EJB2.1 / weblogic 10.3
    I get en nullpointerexception in a weblogic generated class.
    The method in the generated class is :
    private void checkTransaction()
    weblogic.transaction.Transaction tx = (weblogic.transaction.Transaction)
    TransactionHelper.getTransactionHelper().getTransaction();
    if ((tx == null) && (__WL_createTxId == null))
    return;
    else if ((tx == null) && (__WL_createTxId != null))
    if (! true) {
    Loggable l1 = EJBLogger.logaccessedCmrCollectionInDifferentTransactionLoggable("CustomOffice", "officehours");
    throw new IllegalStateException(l1.getMessage());
    else if (!tx.getXid().equals(__WL_createTxId) && ! true ) {
    Loggable l1 = EJBLogger.logaccessedCmrCollectionInDifferentTransactionLoggable("CustomOffice", "officehours");
    throw new IllegalStateException(l1.getMessage());
    I get the nullpointer at the line
    else if (!tx.getXid().equals(__WL_createTxId) && ! true ) {
    I have an EntityBean named CustomOffice, this bean has a collection of Officehours entitybeans.
    When I call ( from a SessionBean with @ejb.transaction type="Supports" )
    Iterator iter = customOfficeLocal.getOfficehours().iterator();
    I get the NullPointeException when not using an transaction, when using a transaction it works.
    But I would llike to call this witout an transaction.

    The method checkTransaction is in a weblogic generated class.
    java.lang.NullPointerException
         at dk.steria.exp.midtier.model.customs.ejb.CustomOffice_up2n56__WebLogic_CMP_RDBMS_officehours_Set.checkTransaction(CustomOffice_up2n56__WebLogic_CMP_RDBMS_officehours_Set.java:644)
         at dk.steria.exp.midtier.model.customs.ejb.CustomOffice_up2n56__WebLogic_CMP_RDBMS_officehours_Set.iterator(CustomOffice_up2n56__WebLogic_CMP_RDBMS_officehours_Set.java:186)
         at dk.steria.exp.midtier.tools.factory.DeclarationFactory.createOfficeHoursTOList(DeclarationFactory.java:1443)
         at dk.steria.exp.midtier.tools.factory.DeclarationFactory.createCustomOfficeTO(DeclarationFactory.java:1415)
    The error comes when I call
    Iterator iter = customOfficeLocal.getOfficehours().iterator();
    in my code.
    I guess it is because I am using a EJB 2.1 entitybean.... that needs a transaction ??????

  • Obtaining Object Methods

    Problem:
    I am working with a list of class which are all subclasses of an abstract class.
    I have created an object of each method by the following code:
    Dent Hor = new Horisontal();
    Dent Hin = new Hinged();
    Dent I = new Instant();
    Dent V = new Vertical();
    ClassType ct = new ClassType();
    Object p, q, r;
    p = ct.makeObject("fa.Instant");
    q = ct.makeObject("fa.Horisontal");
    r = ct.makeObject("fa.Hinged");
    I want to handle each DENT as a DENT, yet each DENT object will know what specific class in the hierachy of DENTs it really belongs to.
    Now i when to get the methods in each of the objects.
    Does anyone know how this can be done?
    Thanks

    Here is a bunch of code, origenally based on what you posted above. It only uses Dent and Horizontal for simplicity, it does the printName as you have above, then it calls a bunch of Dent and Horizontal specific methods. I includ my versions of the Dent and Horizontal classes in the same java file, again, just for simplicity...
    package fa;
    public class Test {
         public Object makeObject(String cn) throws ClassNotFoundException,
                                     InstantiationException,
                                     IllegalAccessException
              Object o = Class.forName(cn).newInstance();
              return o;
         public static void main(String[] args)
              Test ct = new Test();
              Dent Hor = new Horizontal();
              Dent r = null;
              try
                   r = (Dent) ct.makeObject("fa.Horizontal");
              } catch (ClassNotFoundException cnfe)
                   cnfe.printStackTrace();
                   System.exit(1);
              } catch (InstantiationException ie)
                   ie.printStackTrace();
                   System.exit(1);
              } catch (IllegalAccessException iae)
                   iae.printStackTrace();
                   System.exit(1);
              ct.printName(r);
              ct.useMethods(r);
         public void printName(Object o)
              Class c = o.getClass();
              String s = c.getName();
              System.out.println(s);
         public void useMethods(Dent r)
              r.dentMethod0();
              r.dentMethod1();
              r.dentMethod2();
              if (r instanceof Horizontal)
                   ((Horizontal)r).horizMethod3();
    abstract class Dent
         void dentMethod0()
              System.out.println("Dent 0");
         void dentMethod1()
              System.out.println("Dent 1");
         abstract void dentMethod2();
    class Horizontal extends Dent
         void dentMethod1()
              System.out.println("---------------");
              super.dentMethod1();
              System.out.println("Horizontal 1");
              System.out.println("---------------");
         void dentMethod2()
              System.out.println("---------------");
              System.out.println("Horizontal 2");
              System.out.println("---------------");
         void horizMethod3()
              System.out.println("---------------");
              System.out.println("Horizontal 3");
              System.out.println("---------------");
    }

  • Question on View Object method to use to reset a data entry form?

    I am using a transient View Object form for the purpose of collecting and persisting data entered by users in a set of web data forms that span multiple pages. In the Application Module, I create the first row (see below.) After the user submits the last form, I programmatically add the data to the database (later may change to an Entity Object, but right now I don't use one.) So, the data they entered remains in the VO (it only ever has one row.)
    My question is which method do I use to clear out the current set of data values. I tried VO.clearcache() but it deletes the row, and VO.reset() did not clear the data? If the only way is to delete the row, then please advise the best way to re-create the row or re-set the iterator.
    thanks!
    -- sample code to insert initial row in App Module --
    protected void prepareSession(oracle.jbo.Session session) {
    super.prepareSession(session);
    insertTransientViewObjRows();
    private void insertTransientViewObjRows() {
    ViewObject transientvo = getView1();
    transientvo.clearCache();
    transientvo.insertRow(transientvo.createRow());
    ---- in service method after user submits the form and row remains in VO, I have tried: --
    vo1.reset(); // does not delete data from the row
    vo1.clearCache(); // deletes the row

    Thanks. Yes this looks more like what I need. How do I call this method from the client-tier, or from within a service method in my Application Module?
    vo1 = findViewObject("myViewObject");
    row = (MyViewRowImpl)vo1.first();
    row.initDefaults();
    compiler error message received:
    Error(279,21): method initDefaults() has protected access in class oracle.jbo.server.ViewRowImpl
    "Customer applications should not access this class on the client-tier of an application. Instead, the Row interface should be used for client tier access"
    Which Row interface method can I call?
    Message was edited by:
    javaX

Maybe you are looking for