aspose file tools*
The moose likes I/O and Streams and the fly likes Java NullpointerException  while reading BufferedReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Java NullpointerException  while reading BufferedReader" Watch "Java NullpointerException  while reading BufferedReader" New topic
Author

Java NullpointerException while reading BufferedReader

jitamitra
Greenhorn

Joined: Oct 30, 2001
Posts: 3
Hi there!
I have this strange problem where i am getting nullpointer exception while i am trying to open a file with buffered reader. well i am even using a string tokenizer to get some data for the required fields . Is this giving any problem to me (I dont know)

Below is the part of the code where the problem is occuring.

Thanks

Jita

****************************************************************

public class Syn_Anal extends Thread{


public Syn_Anal() throws Exception{
Thread t1 = new Thread(this);
t1.start();
}

public static BufferedWriter parseerr;
private static LineNumberReader infl;
public static BufferedWriter listing;
/*public static final int ADDOP = 100,OSBRACE = 201,CSBRACE = 202, OPBRACE =301,CLBRACE = 302,PROGRAM = 103,ID = 104, ASSGNOP = 105;
public static final int NUM = 555,MULOP = 107, RELOP = 106,ERRORTOK = 888, SCOLN= 401,VAR = 500,FUNCTION = 108,DOT = 109,BEGIN = 110;
public static final int COMMA = 111,COLN = 112, $ = 999,END = 113, ELSE =114, IF = 115, WHILE = 116, INTEGER = 117, REAL = 118;
public static final int ARRAY = 119,DOTDOT = 120,OF = 121,THEN = 122,DO =123,PLUS = 124,MINUS = 125,NOT = 126;*/
public static int ti = 0;
private static String Line ;
private static String check_line = "1";
private static String Attr;
private static String Type;
private static String value;
private static Thread wait;
public static String tokenval;
private static String error;

public static Lexical_Anal lex_syn = new Lexical_Anal();
public static void main(String args[])throws Exception {
parseint();
infl = new LineNumberReader(new FileReader("Testfile.java"));
//listing = new BufferedWriter(new FileWriter("SynList.java"));
}
public static void parseint() throws Exception{
parseerr= new BufferedWriter(new FileWriter("error.txt"));
System.out.println(lex_syn.partoken.size());
System.out.println(lex_syn.partoken.getFirst());
System.out.println("Start of the Parser (!!!)");
//System.out.println(infl.readLine());
program();
}



public static String get_token()throws Exception{
wait = new Thread();
String token =lex_syn.partoken.get(ti).toString();
StringTokenizer st = new StringTokenizer(token);
//parseerr.write(infl.readLine());
Line = st.nextToken();



System.out.println(Line);
String next_tok = st.nextToken() ;
System.out.println(next_tok);
Attr = st.nextToken();
System.out.println(Attr);
Type = st.nextToken();
System.out.println(Type);
value =st.nextToken();
System.out.println(value);
error = st.nextToken();
System.out.println(error);

if(Line.compareTo(check_line) > 0 | | Line.compareTo(check_line) < 0) {<br /> System.out.println("reading the next line from input");<br /> System.out.println(check_line + "Before");<br /> System.out.println(Line + "Bef");<br /> check_line = Line;<br /> System.out.println(check_line + "After");<br /> //try {<br /> String take = infl.readLine(); <br /> //while((take= infl.readLine()) != null) {<br /> parseerr.write(take);<br /> <br /> //}<br /> //}catch(NullPointerException e){}; <br /> // System.out.println(check_line);<br /> <br /> //System.out.println(check_line + "After");<br /> }<br /> if(error.equalsIgnoreCase("9") | | error.equalsIgnoreCase("2")| | error.equalsIgnoreCase("9") | | error.equalsIgnoreCase("3")| |error.equalsIgnoreCase("4") | | error.equalsIgnoreCase("6") | |error.equalsIgnoreCase("5") | | error.equalsIgnoreCase("7")) {<br /> <br /> System.out.println("Hey i got the error" + Line );<br /> parseerr.write( Line + "mmmm Lexical errors");<br /> }<br /> <br /> ti++;<br /> if (next_tok.equalsIgnoreCase("$")) {<br /> System.out.println("Eof Occured: End of Syntax Analysis");<br /> parseerr.close();<br /> System.exit(1);<br /> }<br /> System.out.println(next_tok + "---------> Current Token");
return next_tok;

}


Jita Karcherla
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
jitamitra,
your name does not comply with the JavaRanch Naming Policy.
Please read it and register again
Thank you for your cooperation
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
jitamitra
Greenhorn

Joined: Oct 30, 2001
Posts: 3
Hi Valentin Crettaz

I could not get what you meant by the Naming policy and i am new to this place . The name what i have given is the one i have. I am including my first and last names now . Is that what you are looking for .....

Thanks,
Jita Karch


------------------
Jita Karcherla
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java NullpointerException while reading BufferedReader