Results 1 to 6 of 6
Thread: Error: Null (String Tokenizer)
- 07-11-2012, 01:47 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 14
- Rep Power
- 0
Error: Null (String Tokenizer)
I have spent quite some time to figure out the null error the compiler returns. I think (though i'm not sure) its because st.nextToken at the end of the line doesnot points to any object. Can anybody suggest how to fix this? Thanks
Java Code:import java.io.*; import java.util.StringTokenizer; class FileReadEncrypt { public static void main(String args[]) { try{ // Open and Read the file FileInputStream f1stream = new FileInputStream("Geo Tagger v2_2012-06-28_03-46-08.xml"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(f1stream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); Writer output = null; File file = new File("SampleTest.xml"); output = new BufferedWriter(new FileWriter(file)); String strLine = null; while ((strLine = br.readLine()) != null) { String outputLine1 = ""; String outputLine2 = ""; StringTokenizer st = new StringTokenizer(strLine, "<>", true); while(st.hasMoreTokens()) { String key = st.nextToken();System.out.println(key); //String val = st.nextToken(); if(key.equals(">") && !st.nextToken().equals("<")){ outputLine1 += key; outputLine2 += key; String val = st.nextToken();//System.out.println(val); for ( int i = 0; i < val.length(); ++i ) { char c = strLine.charAt(i); int j = (int) c; int k = j+1; char d = (char) k; outputLine1 += c; outputLine2 += d; } } //else if(key.equals(">")) outputLine1 += key; outputLine2 += key; //} }System.out.println("yasar"); output.write(outputLine2); //System.out.println(outputLine1); System.out.println(outputLine2); } //Close the input and output stream in.close(); output.close(); } //Catch exception if any catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } }
- 07-11-2012, 01:50 PM #2
Member
- Join Date
- Jul 2012
- Posts
- 14
- Rep Power
- 0
Re: Error: Null (String Tokenizer)
For reference, its the st.nextToken() in line #29
- 07-11-2012, 01:59 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 14
- Rep Power
- 0
Re: Error: Null (String Tokenizer)
I tried using a check with st.hasMoreTokens() but it didn't resolve the error either
Edit: problem resolved. Should have spent some more time debugging it :)Last edited by yasarqamar; 07-11-2012 at 03:13 PM.
- 07-11-2012, 03:30 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Error: Null (String Tokenizer)
What does the code look like with that check, as that is the solution to the problem.
Please do not ask for code as refusal often offends.
- 07-11-2012, 03:33 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Error: Null (String Tokenizer)
Oh and:
That first nextToken is lost.Java Code:if(key.equals(">") && !st.nextToken().equals("<")){ ... String val = st.nextToken();//System.out.println(val);
Are you sure you want to do that?Please do not ask for code as refusal often offends.
- 07-12-2012, 11:19 PM #6
Member
- Join Date
- Jul 2012
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
String Tokenizer help
By Arigo in forum New To JavaReplies: 7Last Post: 04-18-2011, 02:03 AM -
String Tokenizer help
By GreenTea in forum New To JavaReplies: 4Last Post: 10-30-2010, 02:44 AM -
String Tokenizer
By hussainian in forum Advanced JavaReplies: 1Last Post: 03-16-2010, 08:58 AM -
String Tokenizer
By viperlasson in forum New To JavaReplies: 1Last Post: 03-09-2010, 01:14 PM -
String Tokenizer
By redasu in forum Advanced JavaReplies: 4Last Post: 02-19-2010, 03:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks