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
Similar Messages
-
Why is my JavaServiceFacade persist() method is receiving NULL object
My jDeveloper version is 11.1.1.3.0
I have a jspx in which i want to save an employee into my DB on the click of submit button.
I have made an entity object(Employee.java) made from a table EMPLOYEE. I then exposed this entity bean using a JavaServiceFacade. This JavaServiceFacade class has a method with signature persistEmployee(Employee employee).
In my UI, i have made made a Submit button by dragging the persistEmployee() method from my DataControls pallette to my jspx, and the actionListener binding for this is ="#{bindings.persistEmployees.execute}".
Now when i click on the submit button, the persistEmployee() method throws an exception which is below...
______ java.lang.IllegalArgumentException: Object: null is not a known entity type_______
I found that the persistEmployee() method is not receiving an Employee object as an argument due to which this error is thrown.
Can somebody pls guide me on what could be the issue.
BELOW ISTHE CODE WHICH I HAVE USED.
.......button code in my jsp.......
<af:commandButton text="Submit"
binding="#{backing_LdapUserCreation.cb5}"
id="cb5"
actionListener="#{bindings.persistEmployees.execute}"
disabled="#{!bindings.persistEmployees.enabled}"/>
.......method code which got generated in teh javaservicefacade..(here the employee argument received by the first line is NULL).....
public Employees persistEmployees(Employees employees) {
System.out.println("IS employees NULL ? = "+employees);
return (Employees)_persistEntity(employees);
.......binding code in my pagedefinition.........
<methodAction id="persistEmployees" RequiresUpdateModel="true"
Action="invokeMethod" MethodName="persistEmployees"
IsViewObjectMethod="false" DataControl="EmployeeService"
InstanceName="EmployeeService.dataProvider"
ReturnName="EmployeeService.methodResults.persistEmployees_EmployeeService_dataProvider_persistEmployees_result">
<NamedData NDName="employees" NDType="model.test.Employees" />
</methodAction>Hi,
when you dragged the persist method from the DataControls panel, a dialog opens that in its lower area shows the argument that the method expects. This argument needs to be pointed to <iterator name> | currentRow | data provider. To do this, click into the method argument value field and click the button on its right to bring up the EL editor. Then expand the iterator node under the Bindings node. Expand currentRow and select dataProvider.
You can do this after creating the method binding as well. Select the PageDef file in the Application Navigator and open the Structure Window. Expand the persist method: it shoudl have a child element. Select the child item and in the Property Inspector set its NDValue property
Frank -
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 ?????? -
SAX XML NullPointerException in character() method
I'm having issues when parsing my xml file. Everything works fine unless I am trying to push values into my parameters Vector.
class SAXLoader extends DefaultHandler {
private static String className, //name of the class for module in xml
methodName, //name of the method for the class
path; //path to jar. should be in URI format
private Vector params; //parameters to the method
private boolean isClassName, //true if element begins className tag
isMethodName, //true if element begins methodName tag
isParameter, //true if element begins parameter tag
isPath; //true if element begins path tag
//=======================init()================================
//opens XML file specified and parses it for className,
//the methodName,and the path to the JAR
//This should be called before doing any of the getter methods
//=============================================================
public void init() {
try {
XMLReader xmlreader = XMLReaderFactory.createXMLReader();
SAXLoader handler = new SAXLoader();
xmlreader.setContentHandler(handler);
xmlreader.setErrorHandler(handler);
try {
FileReader r = new FileReader("myclass.xml");
xmlreader.parse(new InputSource(r));
} catch (FileNotFoundException e) {
System.out.println("File Not Found!");
e.printStackTrace();
} catch (NullPointerException e) {
System.out.println("Parse Error!");
e.printStackTrace();
} catch (Exception e) {
System.out.println("XML Reader Error!");
e.printStackTrace();
public void characters(char ch[], int start, int length) {
String temp = "";
for (int i = start; i < start + length; i++) {
switch (ch) {
case '\\':
// System.out.print("\\\\");
break;
case '"':
// System.out.print("\\\"");
break;
case '\n':
// System.out.print("\\n");
break;
case '\r':
// System.out.print("\\r");
break;
case '\t':
// System.out.print("\\t");
break;
default:
temp += ch[i];
break;
if (isClassName) {
className = temp;
} else if (isMethodName) {
methodName = temp;
} else if (isPath) {
path = temp;
} else if (isParameter) {
System.out.println("zomg!: " + temp);
params.add(temp);
} //end of characters(...
Right there at params.add(temp);
I'm using this DefaultHandler based class to parse an XML file for information regarding a user's own class [its classname, its methodname, and the methods parameters].
Any clues?
Message was edited by:
nick.mancuso
Message was edited by:
nick.mancusoYou don't actually allocate the params Vector, at least not on the code you've posted. You want something like:
private Vector params = new Vector();or better yet:
private List params = new LinkedList();perhaps.
But even better yet...I suspect that having a handful of global temp variables like that isn't going to work. In my experience, when using SAX you pretty much have to create a stack to hold the current place in the XML tree. That's how you traverse trees, with stacks. Then instead of setting isMethodName, isParameter, etc. (which I presume you do in open/close tag handlers) you define an enumeration of values like "class", "method", "parameter", and then have a stack of those values, or something. -
NullPointerException on String methods
All,
I am trying to get date values on the fly and add them to my sql statement. I have a DateWorker class that provides month, day of month and year.
When I use the class in another class, I get NullPointerException. These are just plain ol' String methods, why are they giving me problems. When I run the code on its won, it works fine.
Code:
package mybeans;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Calendar;
public class DateWorker {
public DateWorker dateWorker;
public DateWorker(){
dateWorker = new DateWorker()
public static void main(String[] args){
String m = dateWorker.getMonth();
String dm = dateWorker.getDayOfMonth();
String dw = dateWorker.getDayOfWeek();
String y = dateWorker.getYear();
System.out.println("day of week " + dw + "<BR>");
System.out.println("day of month" + dm + "<BR>");
System.out.println("month " + m + "<BR>");
System.out.println("year " + y + "<BR>");
//get a Calendar instance.
private Calendar cal = Calendar.getInstance();
//gets the current month
public String getMonth(){
int x = cal.get(Calendar.MONTH) + 1;
String s = String.valueOf(x);
return s;
//gets the current day of month
public String getDayOfMonth(){
int x = cal.get(Calendar.DAY_OF_MONTH);
String s = String.valueOf(x);
return s;
//gets the current day of week
public String getDayOfWeek(){
int x = cal.get(Calendar.DAY_OF_WEEK) -1;
String s = String.valueOf(x);
return s;
//gets the current year
public String getYear(){
int x = cal.get(Calendar.YEAR);
String s = String.valueOf(x);
return s;
Edited by: ink86 on Oct 8, 2007 12:57 PMpackage mybeans;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Calendar;
public class DateWorker {
public static void main(String[] args){
DateWorker dateWorker = new DateWorker();
String m = dateWorker.getMonth();
String dm = dateWorker.getDayOfMonth();
String dw = dateWorker.getDayOfWeek();
String y = dateWorker.getYear();
System.out.println("day of week " + dw + "<BR>");
System.out.println("day of month" + dm + "<BR>");
System.out.println("month " + m + "<BR>");
System.out.println("year " + y + "<BR>");
//get a Calendar instance.
Calendar cal = Calendar.getInstance();
//gets the current month
public String getMonth(){
int x = cal.get(Calendar.MONTH) + 1;
String s = String.valueOf(x);
return s;
//gets the current day of month
public String getDayOfMonth(){
int x = cal.get(Calendar.DAY_OF_MONTH);
String s = String.valueOf(x);
return s;
//gets the current day of week
public String getDayOfWeek(){
int x = cal.get(Calendar.DAY_OF_WEEK) -1;
String s = String.valueOf(x);
return s;
//gets the current year
public String getYear(){
int x = cal.get(Calendar.YEAR);
String s = String.valueOf(x);
return s;
} -
NullPointerException on a method declaration?
Hi all,
I'm not sure whether I should be posting this here on on the app server board.
But anyway, I have an ADF application (with ADF Faces) that works fine in JDev 10.1.3, and after some difficulty, I've managed to get it deployed, so that the first page comes up properly in a browser.
When I click on a link in my navigation tree, however, I get an error in the method called by the CommandLink in the tree node. Here's what it is:
javax.faces.FacesException: #{homeBean.treeNavigate}: javax.faces.el.EvaluationException
Caused by [at the bottom]: java.lang.NullPointerException
at mypackage.BasePage.TreeNavigate (BasePage.java:53)
So OK, for some reason my code is firing a null pointer exception in the deployed version. Let's see what it is by checking BasePage.java, line 53:
53) public String treeNavigate() {
A method declaration. That shouldn't be able to throw a NullPointerException, or indeed any other runtime error, should it?
Can anyone shed some light about what might be going on here?
Thanks much,
Avrompublic void drawPictures(int size, Graphics page)
page.drawImage (board, 0, 0, 720, 567, this);
public void paint (Graphics page)
drawPictures (APPLET_WIDTH, page);
private final int APPLET_WIDTH = 720;
board = getImage (getDocumentBase(), "board.jpg"); //inside my init() methodThanks for the quite response. I looked at my code with your suggestions and came up with this:
If I take away my "paint" method, the buttons have no problems, but, of course, no picture comes up. Any ideas?
I was also throw out the fact that this is my first time with GUIs. My teacher saved them to the end last year, got lazy, and then never did them. So if I am using horrible self-taught practices, it would be awesome if you can let me know, so I can improve. Thanks.
Edited by: 7sunami on Feb 22, 2009 6:00 PM -
NullPointerException in Remote method
Hello,
I am trying to reproduce the database sample of the Java Roadmap using EJB's. I have gone through all the steps, deploying went well, compiling too. but when running the selectEJB Client program I get the following messages:
"C:\Program Files\Oracle\JDeveloper 3.1\java\bin\javaw.exe" -mx50m -classpath "U:\Documentation\EJB;C:\Program Files\Oracle\JDeveloper 3.1\lib\jdev-rt.zip;C:\Program Files\Oracle\JDeveloper 3.1\jdbc\lib\oracle8.1.6\classes111.zip;C:\Program Files\Oracle\JDeveloper 3.1\lib\connectionmanager.zip;C:\Program Files\Oracle\JDeveloper 3.1\lib\javax_ejb.zip;C:\Program Files\Oracle\JDeveloper 3.1\aurora\lib\aurora_client.jar;C:\Program Files\Oracle\JDeveloper 3.1\aurora\lib\vbjorb.jar;C:\Program Files\Oracle\JDeveloper 3.1\aurora\lib\vbjapp.jar;C:\Program Files\Oracle\JDeveloper 3.1\aurora\lib\vbjtools.jar;C:\Program Files\Oracle\JDeveloper 3.1\aurora\lib\vbj30ssl.jar;C:\Program Files\Oracle\JDeveloper 3.1\aurora\lib\aurora.zip;C:\Program Files\Oracle\JDeveloper 3.1\sqlj\lib\translator.zip;U:\Documentation\EJB\selectEJBRemoteSource.jar;U:\Documentation\EJB\selectEJBRemoteGenerated.jar;C:\Program Files\Oracle\JDeveloper 3.1\java\lib\classes.zip" selectO8iClient.MyEJBClient
Creating an initial context
Looking for the EJB published as 'test/selectEJBRemote'
Creating a new EJB instance
Caught RuntimeException in remote method; nested exception is:
java.lang.NullPointerException:null
Remote Stack Trace:
java.lang.NullPointerException
at selectEJB.selectEJBClass.ejbCreate(selectEJBClass.java:41)
at oracle.aurora.ejb.gen.test_selectEJBRemote.EjbHome_selectEJBHome.create(EjbHome_selectEJBHome:52)
at selectEJB._tie_selectEJBHome.create(_tie_selectEJBHome.java:53)
at selectEJB._selectEJBHomeImplBase._execute(_selectEJBHomeImplBase.java:65)
at selectEJB._selectEJBHomeImplBase._execute(_selectEJBHomeImplBase.java:53)
at com.visigenic.vbroker.orb.SkeletonDelegateImpl.execute(SkeletonDelegateImpl.java:129)
at oracle.aurora.server.GiopProtocolAdapter.doRequest(GiopProtocolAdapter.java:266)
at com.visigenic.vbroker.orb.GiopProtocolAdapter.dispatchMessage(GiopProtocolAdapter.java:462)
at oracle.aurora.server.ThreadSessionDispatcher.run(ThreadSessionDispatcher.java:92)
at oracle.aurora.server.VCIiopConnection.processRequest(VCIiopConnection.java:62)
at oracle.aurora.server.GiopServer._service(GiopServer.java:82)
at oracle.aurora.server.GiopServer.service(GiopServer.java:191)
at oracle.aurora.net.VirtualCircuit.processRequest(VirtualCircuit.java:201)
at oracle.aurora.net.Presentation.handleRequest(Presentation.java:292)
oracle.aurora.ejb.RemoteRuntimeException: Caught RuntimeException in remote method; nested exception is:
java.lang.NullPointerException:null
Remote Stack Trace:
java.lang.NullPointerException
at selectEJB.selectEJBClass.ejbCreate(selectEJBClass.java:41)
at oracle.aurora.ejb.gen.test_selectEJBRemote.EjbHome_selectEJBHome.create(EjbHome_selectEJBHome:52)
at selectEJB._tie_selectEJBHome.create(_tie_selectEJBHome.java:53)
at selectEJB._selectEJBHomeImplBase._execute(_selectEJBHomeImplBase.java:65)
at selectEJB._selectEJBHomeImplBase._execute(_selectEJBHomeImplBase.java:53)
at com.visigenic.vbroker.orb.SkeletonDelegateImpl.execute(SkeletonDelegateImpl.java:129)
at oracle.aurora.server.GiopProtocolAdapter.doRequest(GiopProtocolAdapter.java:266)
at com.visigenic.vbroker.orb.GiopProtocolAdapter.dispatchMessage(GiopProtocolAdapter.java:462)
at oracle.aurora.server.ThreadSessionDispatcher.run(ThreadSessionDispatcher.java:92)
at oracle.aurora.server.VCIiopConnection.processRequest(VCIiopConnection.java:62)
at oracle.aurora.server.GiopServer._service(GiopServer.java:82)
at oracle.aurora.server.GiopServer.service(GiopServer.java:191)
at oracle.aurora.net.VirtualCircuit.processRequest(VirtualCircuit.java:201)
at oracle.aurora.net.Presentation.handleRequest(Presentation.java:292)
at selectEJB._st_selectEJBHome.create(_st_selectEJBHome.java:68)
at selectO8iClient.MyEJBClient.main(MyEJBClient.java:110)
End...java.io.IOException: read error
I have tried debugging the code and there seems to be a problem with creating the remoteInterface:
selectEJBRemote remoteInterface = homeInterface.create();
I just can't figure out what. Can someone help me?
Thanks,
BennyI have encountered exactly the same problem when creating a BMP Entity Bean. Has someone found a solution yet ?
-
NullPointerException in indexing method
Hi,
I'm writing a simple indexing engine, and it works great - if I'm not indexing a lot of files.
It saves the file paths in a text file, but when I try to index the whole hard disk the file gets
about 1,5 MB large before the NullPointerException occurres.
Here's the indexing method:
private void recursiveIndexing(File folder, PrintWriter printWriter)
File[] filesInDirectory = folder.listFiles();
for (int i = 0; i < filesInDirectory.length; i++) {
if (filesInDirectory.isDirectory())
recursiveIndexing(filesInDirectory[i], printWriter);
else
printWriter.println(filesInDirectory[i].getPath());
}Thanks in advance.Oh, sorry, I was in a hurry when I wrote the post.
Actually it's these two lines who are causing the exception:
for (int i = 0; i < filesInDirectory.length; i++)
recursiveIndexing(filesInDirectory, printWriter);I noticed now, when I tried to index the whole hard drive at my
own computer (which is more powerful than the other one), that
the text file became 6,2 MB large before the exception occurred.
Thanks.
Edited by: Souken on 2008-sep-29 20:17 -
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!
-seveneightn9neNow 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? -
Method persist() don't persist the data.
Hello Experts
I have a problem whem i persist a entity.
Often the instance of entity don't persist when i call method persist().
I don't know what happen. The method don't cause any error, but don't have any registry in the database after passing the persist() method.
Att.
MarcosHi Adrian
Thanks for your quickly reply.
i don't use the method flush. But in other entity, i do the same process and the data is commit in database. i've compared these two entity, and they are equals. the only diference is the quantity of attributes in both.
I try to use the method flush in both entity. In the first is OK, the data is commited. In the second cause one error.
When i don't use the method flush, the same happend, the first commit, the second don't commit, but don't cause error.
Waiting for anwser.
Thanks.
Marcos. -
JPA and JSF - Problem persisting object
Hi all.
I'm having some trouble with JPA, persisting an object to a MySQL table.
Let's say I have a simple bean, Message:
package my.package
import java.io.Serializable;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@Entity
@Table(name="messages")
public class Message implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column(name="message_text")
private String message;
@Column(name="message_author")
private String author;
public String getMessage() {
return this.message;
public void setMessage(String message) {
this.message = message;
public String getAuthor() {
return this.author;
public void setAuthor(String author) {
this.author = author;
}And a controller for this Message bean:
package my.package;
import javax.annotation.Resource;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.transaction.UserTransaction;
public class MessageController {
@PersistenceUnit(unitName="em1")
private EntityManagerFactory emf;
@Resource
private UserTransaction utx;
private Message message;
public Message getMessage() {
return this.message;
public void setMessage(Message message) {
this.message = message;
public String save() {
EntityManager em = null;
String returnValue = "";
try {
em = this.emf.createEntityManager();
utx.begin();
em.persist(this.message);
utx.commit();
returnValue = "success";
} catch(Exception e) {
e.printStackTrace();
returnValue = "failure";
return returnValue;
}Relevant code from the faces-config.xml:
<managed-bean>
<managed-bean-name>MessageController</managed-bean-name>
<managed-bean-class>my.package.MessageController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>message</property-name>
<property-class>my.package.Message</property-class>
<value>#{Message}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>Message</managed-bean-name>
<managed-bean-class>my.package.Message</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>This is my simple persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name ="em1">
<jta-data-source>jdbc/__glfish</jta-data-source>
</persistence-unit>
</persistence>The __glfish resource is all set up via Glassfish to point to my MySQL server, via a MySQLPool.
Can anyone see what I'm doing wrong? The Message doesn't get added to the table in my database, and I get a NullPointerException in the method MessageController.save() on the property MessageController.message - which I have specified in the faces-config.xml. Shouldn't that be enough? What have I missed?Ok, I have (re-)located the problem. It's not my Message property which gets a NullPointerException - it seems like the problem is with my EntityManagerFactory instance. The PersistenceUnit don't get assigned, even though I declare it in my persistence.xml file.
Maybe it is something wrong with my file structure?
The .war file have this structure:
- WEB-INF
- classes
- my
- package
Message.class
MessageController.class
- lib
[external jars goes here]
- META-INF
persistence.xml
faces-config.xml
web.xml
[*.jsp/*.xhtml goes here]Can anyone see what's wrong? -
Adf faces command button, bindings and ejb 3.0 persisting problem
When mapping the persist method to an adf command button it got this error:
1. JBO-29000: java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21.; nested exception is: java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21. -
2. java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21.; nested exception is: java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21. -
Is that because Departments are serialized by the container when the session bean is accessed by the data control to catch the data when the form is populating and entities are detached from the persisting context ? or something else ?
I bind the button to the current row data provider for the departments. Is it correct, isn't ?When mapping the persist method to an adf command button it got this error:
1. JBO-29000: java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21.; nested exception is: java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21. -
2. java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21.; nested exception is: java.lang.IllegalArgumentException: PERSIST impossible sur l'objet détaché : hr.entity.Departments@1b21. -
Is that because Departments are serialized by the container when the session bean is accessed by the data control to catch the data when the form is populating and entities are detached from the persisting context ? or something else ?
I bind the button to the current row data provider for the departments. Is it correct, isn't ? -
Getting the object id after persisting
Is there an easy way of getting the object id after using the persist method? I tried the following code piece but it didn't work. Do I have to run a query? I'm new to JPA and waiting for your suggestions. Thanks..
Bill b = new Bill(); .... .... entityManager.persist(b); int id = b.getId()I tried flushing and refreshing the entity but got an EntityNotFoundException.
Bill b = new Bill();
entityManager.persist(b);
entityManager.flush();
entityManager.refresh(b); // Here where the exception is thrown
int id = b.getId();When I try without refresh, it still get no id -
Cannot invoke method multiply() on null object
Hi ,
when im trying to follow Developing Rich Web Applications With Oracle ADF tutorial in this link http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_55/jdtut_11r2_55_3.html
and in the part ( Add CRUD Operation Components to your Page ) when pressing the CreateInsert i got the error message Cannot invoke method multiply() on null object ,
the logs as below
<Utils> <buildFacesMessage> ADF: Adding the following JSF error message: Cannot invoke method multiply() on null object
java.lang.NullPointerException: Cannot invoke method multiply() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:750)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:727)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:54)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at bc4j_model_EmpDetails_AnnualSalary_null_gs.run(bc4j_model_EmpDetails_AnnualSalary_null_gs.groovy:1)
at oracle.jbo.ExprEval.internalEvaluateGroovyScript(ExprEval.java:1200)
at oracle.jbo.ExprEval.doEvaluate(ExprEval.java:1253)
at oracle.jbo.ExprEval.evaluateForRow(ExprEval.java:1075)
at oracle.jbo.server.AttributeDefImpl.evaluateTransientExpression(AttributeDefImpl.java:2131)
at oracle.jbo.server.ViewRowStorage.getAttributeInternal(ViewRowStorage.java:1827)
at oracle.jbo.server.ViewRowImpl.getAttributeValue(ViewRowImpl.java:1962)
at oracle.jbo.server.ViewRowImpl.getAttributeInternal(ViewRowImpl.java:824)
at oracle.jbo.server.ViewRowImpl.getAttrInvokeAccessor(ViewRowImpl.java:906)
at oracle.jbo.server.ViewRowImpl.getAttribute(ViewRowImpl.java:854)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.internalGetAttributeValueFromRow(JUCtrlValueBinding.java:1213)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getAttributeFromRow(JUCtrlValueBinding.java:764)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getInputValueInRow(JUCtrlValueBinding.java:3004)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getInputValue(JUCtrlValueBinding.java:2852)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getInputValue(JUCtrlValueBinding.java:2841)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlAttrsBinding.getInputValue(FacesCtrlAttrsBinding.java:183)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.internalGet(JUCtrlValueBinding.java:2416)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlAttrsBinding.internalGet(FacesCtrlAttrsBinding.java:275)
at oracle.adf.model.binding.DCControlBinding.get(DCControlBinding.java:749)
at javax.el.MapELResolver.getValue(MapELResolver.java:164)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(Unknown Source)
at com.sun.el.ValueExpressionImpl.getValue(Unknown Source)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at org.apache.myfaces.trinidad.bean.FacesBeanImpl.getProperty(FacesBeanImpl.java:73)
at oracle.adfinternal.view.faces.renderkit.rich.ValueRenderer.getValue(ValueRenderer.java:184)
at oracle.adfinternal.view.faces.renderkit.rich.SimpleInputBaseRenderer.renderContentStyleAttributes(SimpleInputBaseRenderer.java:512)
at oracle.adfinternal.view.faces.renderkit.rich.SimpleInputBaseRenderer.renderNonElementContent(SimpleInputBaseRenderer.java:397)
at oracle.adfinternal.view.faces.renderkit.rich.FormInputRenderer.encodeAllAsNonElement(FormInputRenderer.java:300)
at oracle.adfinternal.view.faces.renderkit.rich.FormElementRenderer.encodeAll(FormElementRenderer.java:160)
at oracle.adf.view.rich.render.RichRenderer.delegateRenderer(RichRenderer.java:1700)
at oracle.adfinternal.view.faces.renderkit.rich.LabeledInputRenderer.renderFieldCellContents(LabeledInputRenderer.java:228)
at oracle.adfinternal.view.faces.renderkit.rich.LabelLayoutRenderer.renderFieldCell(LabelLayoutRenderer.java:528)
at oracle.adfinternal.view.faces.renderkit.rich.LabelLayoutRenderer.encodeAll(LabelLayoutRenderer.java:305)
at oracle.adfinternal.view.faces.renderkit.rich.LabeledInputRenderer.encodeAll(LabeledInputRenderer.java:215)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
at oracle.adfinternal.view.faces.renderkit.rich.PanelFormLayoutRenderer._encodeFormItem(PanelFormLayoutRenderer.java:1088)
at oracle.adfinternal.view.faces.renderkit.rich.PanelFormLayoutRenderer.access$100(PanelFormLayoutRenderer.java:50)
at oracle.adfinternal.view.faces.renderkit.rich.PanelFormLayoutRenderer$FormColumnEncoder.processComponent(PanelFormLayoutRenderer.java:1604)
at oracle.adfinternal.view.faces.renderkit.rich.PanelFormLayoutRenderer$FormColumnEncoder.processComponent(PanelFormLayoutRenderer.java:1523)
at org.apache.myfaces.trinidad.component.UIXComponent.processFlattenedChildren(UIXComponent.java:187)
at org.apache.myfaces.trinidad.component.UIXComponent.processFlattenedChildren(UIXComponent.java:318)
at org.apache.myfaces.trinidad.component.UIXComponent.encodeFlattenedChildren(UIXComponent.java:283)
at oracle.adfinternal.view.faces.renderkit.rich.PanelFormLayoutRenderer._encodeChildren(PanelFormLayoutRenderer.java:420)
at oracle.adfinternal.view.faces.renderkit.rich.PanelFormLayoutRenderer.encodeAll(PanelFormLayoutRenderer.java:208)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
at oracle.adfinternal.view.faces.renderkit.rich.PanelGroupLayoutRenderer._encodeChild(PanelGroupLayoutRenderer.java:447)
at oracle.adfinternal.view.faces.renderkit.rich.PanelGroupLayoutRenderer.access$1500(PanelGroupLayoutRenderer.java:30)
at oracle.adfinternal.view.faces.renderkit.rich.PanelGroupLayoutRenderer$EncoderCallback.processComponent(PanelGroupLayoutRenderer.java:734)
at oracle.adfinternal.view.faces.renderkit.rich.PanelGroupLayoutRenderer$EncoderCallback.processComponent(PanelGroupLayoutRenderer.java:637)
at org.apache.myfaces.trinidad.component.UIXComponent.processFlattenedChildren(UIXComponent.java:187)
at org.apache.myfaces.trinidad.component.UIXComponent.processFlattenedChildren(UIXComponent.java:318)
at org.apache.myfaces.trinidad.component.UIXComponent.encodeFlattenedChildren(UIXComponent.java:283)
at oracle.adfinternal.view.faces.renderkit.rich.PanelGroupLayoutRenderer.encodeAll(PanelGroupLayoutRenderer.java:360)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
at oracle.adfinternal.view.faces.renderkit.rich.DecorativeBoxRenderer.encodeFacet(DecorativeBoxRenderer.java:440)
at oracle.adfinternal.view.faces.renderkit.rich.DecorativeBoxRenderer._encodeCenterPane(DecorativeBoxRenderer.java:704)
at oracle.adfinternal.view.faces.renderkit.rich.DecorativeBoxRenderer.encodeAll(DecorativeBoxRenderer.java:380)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
at oracle.adfinternal.view.faces.renderkit.rich.DecorativeBoxRenderer.encodeFacet(DecorativeBoxRenderer.java:440)
at oracle.adfinternal.view.faces.renderkit.rich.DecorativeBoxRenderer._encodeCenterPane(DecorativeBoxRenderer.java:704)
at oracle.adfinternal.view.faces.renderkit.rich.DecorativeBoxRenderer.encodeAll(DecorativeBoxRenderer.java:380)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
at oracle.adfinternal.view.faces.renderkit.rich.PanelStretchLayoutRenderer.encodeCenterFacet(PanelStretchLayoutRenderer.java:879)
at oracle.adfinternal.view.faces.renderkit.rich.PanelStretchLayoutRenderer._encodeCenterPane(PanelStretchLayoutRenderer.java:1294)
at oracle.adfinternal.view.faces.renderkit.rich.PanelStretchLayoutRenderer._encodeMiddlePanes(PanelStretchLayoutRenderer.java:351)
at oracle.adfinternal.view.faces.renderkit.rich.PanelStretchLayoutRenderer.encodeAll(PanelStretchLayoutRenderer.java:316)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(CoreRenderer.java:641)
at oracle.adf.view.rich.render.RichRenderer.encodeAllChildrenInContext(RichRenderer.java:3062)
at oracle.adfinternal.view.faces.renderkit.rich.FormRenderer.encodeAll(FormRenderer.java:274)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(CoreRenderer.java:641)
at oracle.adf.view.rich.render.RichRenderer.encodeAllChildrenInContext(RichRenderer.java:3062)
at oracle.adfinternal.view.faces.renderkit.rich.DocumentRenderer.encodeAll(DocumentRenderer.java:1277)
at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at oracle.adfinternal.view.faces.component.AdfViewRoot.encodeAll(AdfViewRoot.java:91)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399)
at org.apache.myfaces.trinidadinternal.application.ViewDeclarationLanguageFactoryImpl$ChangeApplyingVDLWrapper.renderView(ViewDeclarationLanguageFactoryImpl.java:350)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:165)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._renderResponse(LifecycleImpl.java:1027)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:334)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:232)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:173)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:122)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:293)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:199)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:180)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
<Utils> <buildFacesMessage> ADF: Adding the following JSF error message: Cannot invoke method multiply() on null object
any help please ?Thanks Frank ,
really i've already downloaded the ZIP of the final application , but the same error message ,
when removing the Annual salary ( Which is a new Attribute ( not DB column) Salary * 12 ) every think is fine and no more error message ,there is no null salary all the employees have a salary , my JDeveloper Version is 11.1.2.1.0
also , because of the EmpDetails is based on the query
FROM EMPLOYEES Employees, DEPARTMENTS Departments
WHERE Employees.DEPARTMENT_ID = Departments.DEPARTMENT_ID
and the Department id is non editable value , that means even if you add a new user u cant never check this user in this interface , u can check this user only on DB (SQL) level .
Edited by: 876602 on Jul 1, 2012 5:17 AM -
Input/Output And Method Not Found Problem
Ok so firstly I think I should apologise on two fronts.
Firstly, 'cause this is probably posted in the wrong board but I'm not sure this was suitable for the Swing board just 'cause I've been using Swing? And secondly 'cause the code I'm gonna post is so shoddy I would think this constitutes as flaim-bait. >_>
In my defense this is purely for a little class project to give something to write some documentation on so I'm really not too bothered about the efficiency or ace-mazingness of the end result. I just want it to work.
To the problem at hand.
I'm trying to write a program that asks the user a question and then outputs their answer to a file, from which a tally of answers can later be made for the purpose of displaying "results".
My problem is I've been having problems with the input/output of saving the answers given to the program.
I'm still learning and input/output is probably my weakest subject (other than, y'know, being good at Java). I've had a bash at it in the following code but all it does it overwrite what is in the file with a single answer so no list of results accumulate. I generally don't have an idea what to try for that one so any pointers would be appreciated.
Also, my second problem is, in trying to gather results by tallying what is contained in the file, I've run across a problem with the charAt() method not being found and I'm not sure why. Isn't that method a part of java.lang?
Here's the code thus far:
//libraries
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.io.*;
class CaseStudy {
public static void main(String args[]) {
GUI maininterface = new GUI();
maininterface.setupMenu();
maininterface.display();
class GUI {
//for the actionlisteners
int whatframe = 0;
//creates mainframe and border content panel
JFrame mainframe = new JFrame("Survey Client");
JPanel borderpanel = new JPanel(), bottompanel = new JPanel();
JButton quizbutton = new JButton("Take the quiz"), tallybutton = new JButton("Show Results"), submitbutton = new JButton("Submit Results"), menubutton = new JButton("Return To Menu");
QuizQuestions toppanel = new QuizQuestions();
QuizResults toppanel2 = new QuizResults();
GUI() {
//sets border in borderpanel, this spaces the main content in from the sides of the window
borderpanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
//sets up the frame and panels and adds on borders
mainframe.setDefaultCloseOperation(mainframe.EXIT_ON_CLOSE); // exits java when clicking on close on main frame
mainframe.getContentPane().add(borderpanel); // adds the panel as a component to the frame, the panel can hold stuffs
borderpanel.setLayout(new BoxLayout(borderpanel, BoxLayout.PAGE_AXIS));// page_axis means it'll layout vertically
bottompanel.setLayout(new BoxLayout(bottompanel, BoxLayout.LINE_AXIS));// line_axis means it'll layout horizontally
//gives button an action
quizbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
setupQuiz();
tallybutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
if(whatframe == 1) setupResults();
else {
int rusure = JOptionPane.showConfirmDialog(null, "Are you sure you wish to show results? Any current quiz answers won't be saved.", "Please Choose One", JOptionPane.YES_NO_OPTION);
if(rusure == JOptionPane.YES_OPTION) setupResults();
menubutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
setupMenu();
submitbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
toppanel.doQuiz();
borderpanel.add(bottompanel);
public void setupMenu() {
if(whatframe == 3) {
bottompanel.remove(menubutton);
borderpanel.remove(toppanel2);
whatframe = 1;
//adds components and lays them out
bottompanel.add(quizbutton);
bottompanel.add(Box.createRigidArea(new Dimension(0,10)));
bottompanel.add(tallybutton);
display();
public void setupQuiz() {
bottompanel.remove(quizbutton);
bottompanel.remove(Box.createRigidArea(new Dimension(0,10)));
bottompanel.remove(tallybutton);
whatframe = 2;
bottompanel.add(submitbutton);
bottompanel.add(Box.createRigidArea(new Dimension(0,10)));
bottompanel.add(tallybutton);
borderpanel.add(toppanel);
display();
public void setupResults() {
if(whatframe == 1) {
bottompanel.remove(quizbutton);
bottompanel.remove(Box.createRigidArea(new Dimension(0,10)));
bottompanel.remove(tallybutton);
else {
bottompanel.remove(submitbutton);
bottompanel.remove(Box.createRigidArea(new Dimension(0,10)));
bottompanel.remove(tallybutton);
borderpanel.remove(toppanel);
whatframe = 3;
bottompanel.add(menubutton);
borderpanel.add(toppanel2);
display();
public void display() {
//sets the size of the frame around it's components and then shows it
mainframe.pack();
mainframe.setVisible(true);
mainframe.validate(); //makes referenced container relayout it's components
class QuizQuestions extends JPanel {
LoadingSaving loadsave = new LoadingSaving();
JPanel popm = new JPanel(), pop1 = new JPanel(), pop2 = new JPanel(), pop3 = new JPanel(), pop4 = new JPanel();
JFormattedTextField ques = new JFormattedTextField(), op1 = new JFormattedTextField(), op2 = new JFormattedTextField(), op3 = new JFormattedTextField(), op4 = new JFormattedTextField();
JButton bop1 = new JButton("1"), bop2 = new JButton("2"), bop3 = new JButton("3"), bop4 = new JButton("4");
char answer;
QuizQuestions() {
popm.setLayout(new BoxLayout(popm, BoxLayout.PAGE_AXIS));
pop1.setLayout(new BoxLayout(pop1, BoxLayout.LINE_AXIS));
pop2.setLayout(new BoxLayout(pop2, BoxLayout.LINE_AXIS));
pop3.setLayout(new BoxLayout(pop3, BoxLayout.LINE_AXIS));
pop4.setLayout(new BoxLayout(pop4, BoxLayout.LINE_AXIS));
this.add(popm);
popm.add(ques);
popm.add(pop1);
popm.add(pop2);
popm.add(pop3);
popm.add(pop4);
pop1.add(op1);
pop1.add(bop1);
pop2.add(op2);
pop2.add(bop2);
pop3.add(op3);
pop3.add(bop3);
pop4.add(op4);
pop4.add(bop4);
//sets up question text fields
ques.setEditable(false);
op1.setEditable(false);
op2.setEditable(false);
op3.setEditable(false);
op4.setEditable(false);
bop1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
answer = 'a';
bop2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
answer = 'b';
bop3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
answer = 'c';
bop4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e1) {
answer = 'd';
Question1();
public void doQuiz() {
loadsave.save(answer);
public void Question1() {
ques.setValue("Who's your favourite X-Men character?");
op1.setValue("Cyclops");
op2.setValue("Xavier");
op3.setValue("Wolverine");
op4.setValue("Rogue");
class QuizResults extends JPanel {
LoadingSaving loadsave = new LoadingSaving();
JPanel popm = new JPanel();
JFormattedTextField op1 = new JFormattedTextField(), op2 = new JFormattedTextField(), op3 = new JFormattedTextField(), op4 = new JFormattedTextField();
int[] answerarray = new int[4];
QuizResults() {
popm.setLayout(new BoxLayout(popm, BoxLayout.PAGE_AXIS));
this.add(popm);
popm.add(op1);
popm.add(op2);
popm.add(op3);
popm.add(op4);
op1.setEditable(false);
op2.setEditable(false);
op3.setEditable(false);
op4.setEditable(false);
answerarray = loadsave.load();
op1.setValue(answerarray[0]);
op2.setValue(answerarray[1]);
op3.setValue(answerarray[2]);
op4.setValue(answerarray[3]);
class LoadingSaving {
public void save(char answer) {
FileReader fr;
FileWriter fw;
BufferedReader br;
String s;
try {
//ERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERROR
fr = new FileReader("casestudyoutput.txt");
fw = new FileWriter("casestudyoutput.txt");
br = new BufferedReader(fr);
if (br.readLine() == null) s = "x";
else s = br.readLine();
s = s + answer;
fw.write(s);
fr.close();
fw.close();
//ERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERROR
catch(FileNotFoundException exc) {
JOptionPane.showMessageDialog(null, "File not found.");
return;
catch(IOException exc) {
JOptionPane.showMessageDialog(null, "Something bad happened.");
return;
public int[] load() {
FileReader fr;
BufferedReader br;
int[] answerarray = new int[3];
String s;
long length;
int a = 0, b = 0, c = 0, d = 0;
answerarray[0] = 0;
answerarray[1] = 0;
answerarray[2] = 0;
answerarray[3] = 0;
try {
fr = new FileReader("casestudyoutput.txt");
br = new BufferedReader(fr);
if (br.readLine() == null) return answerarray;
else s = br.readLine();
length = s.length();
for(int i = 0; i < length; i++) {
char ch = charAt(i); //ERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERROR
switch(ch) {
case 'a':
a++;
break;
case 'b':
b++;
break;
case 'c':
c++;
break;
case 'd':
d++;
break;
answerarray[0] = a;
answerarray[1] = b;
answerarray[2] = c;
answerarray[3] = d;
fr.close();
catch(FileNotFoundException exc) {
JOptionPane.showMessageDialog(null, "File not found.");
return answerarray;
catch(IOException exc) {
JOptionPane.showMessageDialog(null, "Something bad happened.");
return answerarray;
return answerarray;
}Any pointers/tips/solutions/angry posts to tell me to stop trying to learn Java would be greatly appreciated.
Thanks in advance!
Oh, and in trying to work with it a bit further I realised I'm having a few problems with runtime errors due to exceptions. The first was due to the array being assigned out of bounds (fixed in the above code). But the second reads the following:
Exception in thread "main" java.lang.NullPointerException
at Loadingsaving.load(CaseStudy.java:330)
at QuizResults.(init)(CaseStudy.java.259)
at GUI.(init)(CaseStudy.java:34)
at CaseStudy.main(CaseStudy.java:15)Not quite sure what this one means or how to handle it. =\
Edited by: ThePermster on May 19, 2008 8:08 AMA NullPointerException means a method has been called on a null object, or a variable that isn't pointing to any object. Your Exception points to line 330, which is:
length = s.length();A NPE on that line means that s is null. So let's look at where s is set:
if (br.readLine() == null) return answerarray;
else s = br.readLine();s gets it's value from br.readLine(), so that method must be returning null. You have a logical error here. Look at your If-Else. It reads a line, makes sure it isn't null...then it reads another line. Well what if that line is null? You are performing 2 reads here instead of 1.
Since your If condition returns a value, there's no need for an Else. The code will continue on until it reaches another return. Try this:
s = br.readLine();
if (s == null) return answerarray;
Maybe you are looking for
-
All Background Jobs Are cancelled
Hi all, I make a new server by restoreing backup of our production server and SAP is running well.But when I schedule any back ground jobs all jobs are cancelled.Due to this I am not able to run SGEN.Even when I manually schedule any back ground jobs
-
How can i use the same communication channel to place the file in 2 differe
Hello Guys, We have a requirement where I need to archive the file that i am sending to the legacy FTP server in a Idoc to file scenario. How can i place the file in 2 different locations. In this case place the file in the FTP server and a copy of i
-
Windows Explorer Refuses to Open Folders In Same Window
I have Windows Vista Ultimate SP1. Under Organize->Folder and Search Options->Browse folders I have the radio button, "Open each folder in the same window" checked. However, Vista refuses to do so and opens each folder in its own window. This does no
-
Hello, I didn't find any documentation on Knowledge Modules Task Hierarchy groups and their meaning. I mean groups like "Execution Unit Begin" or "Mapping Cleanup" at Tasks tab of KM edit window. I remember reading something like "Mapping Cleanup tas
-
Hi there! I've just started using the trial for Adobe Captivate and I love the program...bar this one snag! Whenever I'm recording something (while working in Flash or Photoshop), pressing the Alt Key seems to freeze the screen up for a few seconds,