File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Exeception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exeception in thread" Watch "Exeception in thread" New topic
Author

Exeception in thread

mike hew
Greenhorn

Joined: Oct 26, 2006
Posts: 27
OK, I fix the three C's problem, ok I can't spell, lol.

Now I have no error's but when I excute the program I get this:

Big Bank: Monthly Checking Account Activity


----------- Account ----------- Beginning With- Ending Over- Credit Cd

Name Id Type Balance + Deposit - drawal - Fee = Balance draft Advance

Exception in thread "main" java.lang.NullPointerException

at CheckingAccountsTest.handleAccount(CheckingAccountsTest.java :103)

at CheckingAccountsTest.main(CheckingAccountsTest.java:56)


G:\ ~1>



The Pseudo code state's this
WHILE (myFile.getEofFound() IS FALSE)
A-1-2-09) DEFINE a String Array named myFields, and ASSIGN it the value myFile.getCsvRecordFieldArray()
A-1-2-10) IF (myFields[indexForAccountType].equals(CheckingAccount.getAccountType()))
A-1-2-11) INSTANTIATE a local variable named currentAccount of class CheckingAccount, passing the following arguments:
A-1-2-12) myFields[indexForAccountId], myFields[indexForFirstName], myFields[indexForLastName],
A-1-2-13) Double.parseDouble(myFields[indexForBalance])
A-1-2-14) CALL method handleAccount of this class, passing the following arguments: currentAccount, myFile, myFields
A-1-2-15) ASSIGN null TO currentAccount
A-1-2-16) ELSE
A-1-2-17) INSTANTIATE a local variable named currentAccount of class CheckingAccountPlus, passing the following arguments:
A-1-2-18) myFields[indexForAccountId], myFields[indexForFirstName], myFields[indexForLastName],
A-1-2-19) Double.parseDouble(myFields[indexForBalance])
A-1-2-20) CALL method handleAccount of this class, passing the following arguments: currentAccount, myFile, myFields
A-1-2-21) ASSIGN null TO currentAccount
A-1-2-22) END IF
A-1-2-23) END WHILE

WHILE (myFile.getEofFound() IS FALSE AND currentAccount.getAccountId().equals(myFields[indexForAccountId]))
A-1-3-07) IF (myFields[indexForRecordType].equals(recordTypeForDeposit))
A-1-3-08) CALL method handleDeposit with the following argument list: currentAccount,
A-1-3-09) Double.parseDouble(myFields[indexForDepositAmount]
A-1-3-10) ELSE
A-1-3-11) CALL method handleWithdrawal with the following argument list: currentAccount,
A-1-3-12) Double.parseDouble(myFields[indexForWithdrawalAmount]
A-1-3-13) END IF
A-1-3-14) CALL method myFile.readARecord, which reads the next deposit or withdrawal record, if any, for this customer
A-1-3-15) CALL method myFile.getCsvRecordFieldArray and ASSIGN its return value to myFields, a String array. This makes the value from the
A-1-3-16) fields in the record just read available for access as elements in the myFields string array
A-1-3-17) END WHILE
WHILE (myFile.getEofFound() IS FALSE AND currentAccount.getAccountId().equals(myFields[indexForAccountId]))
A-1-4-07) IF (myFields[indexForRecordType].equals(recordTypeForDeposit))
A-1-4-08) CALL method handleDeposit with the following argument list: currentAccount,
A-1-4-09) Double.parseDouble(myFields[indexForDeposit]
A-1-4-10) ELSE
A-1-4-11) CALL method handleWithdrawal with the following argument list: currentAccount,
A-1-4-12) Double.parseDouble(myFields[indexForWithdrawal]
A-1-4-13) END IF
A-1-4-14) CALL method myFile.readARecord, which reads the next deposit or withdrawal record, if any, for this customer
A-1-4-15) CALL method myFile.getCsvRecordFieldArray and ASSIGN its return value to myFields, a String array. This makes the value from the
A-1-4-16) fields in the record just read available for access as elements in the myFields string array
A-1-4-17) END WHILE


pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
Hi

i did neither read your code nor the pseudocode... it's just too much :-)

But did you investigate the Exception message a little further ?
Exception in thread "main" java.lang.NullPointerException

at CheckingAccountsTest.handleAccount(CheckingAccountsTest.java :103)


Means that a NullPointerException (often called a NPE) occured. This happend on Line 103 of the CheckingAccountsTest.java file.

A NPE occurs when you try to invoke a method or access a field on a reference which is null:

e.g.


SO whenever you run this program and the "someCondition" holds true you'll get a NPE.
Now check your code, especialy what you do on line 103 and make sure this piece of code is not executed when the reference is null OR make sure the reference is never null (depends on your program what the right solution would be)

pascal
Trupti Mehta
Ranch Hand

Joined: Oct 08, 2000
Posts: 79

Firstly I would say, pascalbetz have made you understand what is the Exception & what does it stand for.

As the code is very big, its difficult to figure out line #'s. Your mail error point seems to be in line 103 which is called from line 56. I believe its somewhere in myFile.readARecord() or handleAccount(currentAccount, myFile, myFields); OR String []myFields = myFile.getCsvRecordFieldArray(); - the array might not be filled properly or any index that you are accessing in if() is null. To figure out, which line is creatng the problem, write a (SOP) i.e. System.out.println("Read Record"); SOP("Gof Fields");, SOP("Created currentAccount") such message after readARecord(), getCsv...() & before calling handleAccount(). This will help you identify & also confirm which line is causing the error or is run successfully. The error can also be while creating currentAccount object.

Once you know, which line is creating NullPointerException, you may also know the reason behind that & thus solve your problem. If still, you need any help, inform us. We are here to help you out.


Trupti


Regards,
Trupti (SCJP)
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Don't post the same question in multiple forums. It wastes people's time answering it in one when it has already been answered in the other.


Joanne
 
Consider Paul's rocket mass heater.
 
subject: Exeception in thread
 
Similar Threads
Not compiling right?
Exception in thread
Output errors in main
cannot find symbol
might not have been initialized