I have the following questions 1. Is there some way to find the end of file is reached. 2. Also any insight, if its is possible to read a Ms-Word directly or save it to txt file 3. The curent code which is as follows throws a null pointer exception whenever bufferedReader.readLine() reads null. System.out.println(".........Inside readMyFile");BufferedReader br = null;String line = null; String num_Of_Products = null;

According to the API Documentation: public String readLine() Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached

Let me clarify this concept for you:

This is incorrect. if line.length() is 0 the String object is empty (i.e. a blank line). If you called line.length() on a null line you would get a null pointer exception. Check for null by comparing line==null.

2. Also any insight, if its is possible to read a Ms-Word directly or save it to txt file

If one is able to read in a file using BufferedReader, one may postulate that one can write a txt file using BufferedWriter. [ December 09, 2003: Message edited by: Joe Ess ]

I was initially checking for line == null, it used to give me Null Pointer Exception. so i tried the other way checking line.length = 0; but since i found another solution to access Word and Excel directly through jakarta POIs, i started looking into POI API. So whether i got a solution to skip empty lines in ASC...Answer is no. I will really appreicate, if you can throw some light into this as i am curious to know why its throwing me that Null Pointer Error. Thanks for answering my questions Joe, I really appreciate it.

Originally posted by vikram nalagampalli: I was initially checking for line == null, it used to give me Null Pointer Exception.

No it will not. Were you calling line.equals() by any chance? line == null evaluates the String handle "line". If line is null, this comparison returns true. line.equals() invokes a method on the String object the handle line points to. If line is null, you will get a null pointer exception.

It is throwing me a Null Pointer exception, even before it reaches the IF block (i.e)The very Moment CurrentRow is null Well, look at the stack trace. It should tell you exactly which line is throwing the exception. Find that line number in the appropriate code and look at it. If you can't tell why it's throwing NullPointerException, then show us which line it is. That will be much easier than us trying to guess. [ December 15, 2003: Message edited by: Jim Yingst ]

Forgot to Include Exception for the above Message The line Number Refers to the one bolded above.....Any cooments will be greatly appreicated. Thanksjava.lang.NullPointerException at com.so.wordxml.WordXMLMain.getTitle(WordXMLMain.java:799) at com.so.wordxml.WordXMLMain.createTitle(WordXMLMain.java:872) at com.so.wordxml.WordXMLMain.actionPerformed(WordXMLMain.java:119) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1461) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1515) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:392) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:264) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:254) at java.awt.Component.processMouseEvent(Component.java:3799) at java.awt.Component.processEvent(Component.java:3628) at java.awt.Container.processEvent(Container.java:1195) at java.awt.Component.dispatchEventImpl(Component.java:2678) at java.awt.Container.dispatchEventImpl(Container.java:1244) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java(Compiled Code)) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java(Compiled Code)) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2252) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2161) at java.awt.Container.dispatchEventImpl(Container.java:1231) at java.awt.Window.dispatchEventImpl(Window.java:964) at java.awt.Component.dispatchEvent(Component.java:2581) at java.awt.EventQueue.dispatchEvent(EventQueue.java:434) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:172) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:131) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:126) at java.awt.EventDispatchThread.run(EventDispatchThread.java:118)

Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671

posted Dec 16, 2003 11:33:00

0

[B] [/B] If that's the line that's throwing a NullPointerException, then something to the left of a . is null. Not "null", but null. Try this: