• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System.out.println not responding ?

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I've following piece of code which gets inserts a few records into an ArrayList and then try to display them with System.out.println on the Java console. However it is not displaying anything, no runtime errors either.
Maybe some can see some obvious flaw this time:

TIA :-)
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your posted code doesn't include a runnable Java program - no main method.
As I see things, the only System.out.println occurs during the course of a for-loop in the init method. The init method is invoked from the insertTXRecord. But I don't see anything calling the insertTXRecord method.
If a main method is inserted, and the insertTXRecord method invoked, then the program throws a ClassCastException since a String that was inserted into an ArrayList is cast to a TXRecord. That's not allowed.
Also, are you sure you want to create two new ArrayLists and discard the old ones each time insertTXRecord is called?
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its no good, Dirk, the moment I mod the code, Java console reports runtime NullPointerException. Even though insertTXRecord() method is called rather than TXRecord().

This is the startup applet that "loads" TXRecord *and* creates the ArrayLists for the first and only time for a given thread :

And this is one of the applet which accesses the insertTXRecord(String, String) in TXRecord:

I'm sure at the end I'd kick myself, but at the moment I can't see the wood for the trees...
TIA :-)
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The above variation of my codes yield this disheartening Java console output

system datetime stamp: Feb 27, 2004 5:19:10 PM
java.lang.NullPointerException
at ConfirmationFrame.TXRecord(ConfirmationFrame.java:341)
...
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I could any println to work, I'd be much further... :-(
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public void TXRecord() {
// get the static field where pointer to the instance of TXRecord is stored...
txrecord = TXRecord.selfRef;
// now you can call any methods in TXRecord... OK LETS SEE
System.out.println("Brfore");
txrecord.insertTXRecord("yyyyy", "zzzzz");
System.out.println("After");
}

Jus give 2 print stmt berfore and after below statement
txrecord.insertTXRecord("yyyyy", "zzzzz");
Is it printing After???
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Matthew.
Tried your suggestion

And following is the Java console output, so obviously something very bad happened in between...

system datetime stamp: Feb 27, 2004 11:40:00 PM
Before
java.lang.NullPointerException at ConfirmationFrame$prdDtlActionListener.actionPerformed(ConfirmationFrame.java:329)
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

As far as I can see, acctName is never set/ never assigned a value.
Therefor you get the NPE.
reply
    Bookmark Topic Watch Topic
  • New Topic