469,282 Members | 2,034 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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

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
3 7308
itsraghz
127 100+
"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
ohadr
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
itsraghz
127 100+
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.

Similar topics

7 posts views Thread by news | last post: by
9 posts views Thread by tiyaramunna | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.