Results 1 to 6 of 6
  1. #1
    yasarqamar is offline Member
    Join Date
    Jul 2012
    Posts
    14
    Rep Power
    0

    Default 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());
      }
      }
    }

  2. #2
    yasarqamar is offline Member
    Join Date
    Jul 2012
    Posts
    14
    Rep Power
    0

    Default Re: Error: Null (String Tokenizer)

    For reference, its the st.nextToken() in line #29

  3. #3
    yasarqamar is offline Member
    Join Date
    Jul 2012
    Posts
    14
    Rep Power
    0

    Default 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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Error: Null (String Tokenizer)

    Oh and:
    Java Code:
    if(key.equals(">") && !st.nextToken().equals("<")){
    ...
        String val = st.nextToken();//System.out.println(val);
    That first nextToken is lost.
    Are you sure you want to do that?
    Please do not ask for code as refusal often offends.

  6. #6
    yasarqamar is offline Member
    Join Date
    Jul 2012
    Posts
    14
    Rep Power
    0

    Default Re: Error: Null (String Tokenizer)

    No, i changed my code a little bit and then the earlier check worked. plus i spotted the same error too. but thanks anyways :)

Similar Threads

  1. String Tokenizer help
    By Arigo in forum New To Java
    Replies: 7
    Last Post: 04-18-2011, 02:03 AM
  2. String Tokenizer help
    By GreenTea in forum New To Java
    Replies: 4
    Last Post: 10-30-2010, 02:44 AM
  3. String Tokenizer
    By hussainian in forum Advanced Java
    Replies: 1
    Last Post: 03-16-2010, 08:58 AM
  4. String Tokenizer
    By viperlasson in forum New To Java
    Replies: 1
    Last Post: 03-09-2010, 01:14 PM
  5. String Tokenizer
    By redasu in forum Advanced Java
    Replies: 4
    Last Post: 02-19-2010, 03:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •