By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

help with "Exception in thread "main" java.lang.NullPointerException"

P: 2
hi,
i get Exception in thread "main" java.lang.NullPointerException
when i run my application.
the exact error is:
"Exception in thread "main" java.lang.NullPointerException
at sortmergejoin.MergeJoin.Field(MergeJoin.java:204)
at sortmergejoin.MergeJoin.SMJoin(MergeJoin.java:84)
at sortmergejoin.MergeJoin.<init>(MergeJoin.java:34)
at sortmergejoin.Main.main(Main.java:24)
Java Result: 1"

it reffer to the MergeJoin class in:
Expand|Select|Wrap|Line Numbers
  1.  
  2.     /****** get line from the page frame ******/
  3.     public String  Line(Frame frame,int lineNo){
  4.         Page page = frame.getFrame();
  5.         String line = page.getLine(lineNo);     
  6.         //frame.Free();
  7.         return line;
  8.     }
  9.  
  10.     /******** get the Position Field *********/
  11.      public String  Field(Frame frame,int lineNo){
  12.         String []recLine=null;       
  13.         String line;
  14.         line = Line(frame,lineNo);
  15. //        recLine = line.split(" ");
  16.         return recLine[POSITION];
  17.     }
  18.  
can enyone help me ?
thanks.
Nov 6 '08 #1
Share this Question
Share on Google+
3 Replies


100+
P: 127
"Exception in thread "main" java.lang.NullPointerException
at sortmergejoin.MergeJoin.Field(MergeJoin.java:204)
Look at the line #204 and the object what you are passing is NULL. that's why this error. Just initialize the object with a proper, non-null value and run it again.
Nov 6 '08 #2

P: 2
tanks for your reply.
the correct code part is:
public String Field(Frame frame,int lineNo){
String []recLine ;
String line;
line = Line(frame,lineNo);
recLine = line.split(" ");
return recLine[POSITION];
}

and i still get this error.
Nov 6 '08 #3

100+
P: 127
tanks for your reply.
the correct code part is:
public String Field(Frame frame,int lineNo){
String []recLine ;
String line;
line = Line(frame,lineNo);
recLine = line.split(" ");
return recLine[POSITION];
}

and i still get this error.
That's fine. Use the "Code Tags" for the neat look and feel of Java code.

Expand|Select|Wrap|Line Numbers
  1. public String Field(Frame frame,int lineNo){
  2. String []recLine ;
  3. String line;
  4. line = Line(frame,lineNo);
  5. recLine = line.split(" ");
  6. return recLine[POSITION];
  7. }
What is the POSITION here? What exatly the Line(a,b) method returns here? I thought it was a Constructor but then I got to know you are NOT following the standards and you have the all the methods with the first letter capital (Line(), Field() etc.,).

Just check the return value of Line(frame,lineNo) -- which you assign to "line". It is NULL and thats why you get a NullPointerException in the next line when you invoke split() on it.
Nov 6 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.