Hi, I have a problem where when I try to convert a string to an int, an error comes up. I'm converting the string from a text file so that probably has something to do with it. The text file has nothing on it, so I would think it would read, ""(nothing). Here is the relevant code:
static File file = new File("temp"); static String dir = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4 ); File rfile3 = new File(dir + "linenum.txt"); ... FileInputStream fis4 = null; BufferedInputStream bis4 = null; DataInputStream dis4 = null; ... fis4 = new FileInputStream(rfile3); bis4 = new BufferedInputStream(fis4); dis4 = new DataInputStream(bis4); String rlinenumRead = dis4.readLine(); System.out.println(rlinenumRead); //This line yields "null" if(rlinenumRead.equals(null)||rlinenumRead.equals("")||rlinenumRead.equals("null")) //** { rlinenumRead.equals("0"); } int rlinenumInt = Integer.parseInt(rlinenumRead);
**=I'm trying multiple possibilities of what it could read as.
Here is the error I'm getting:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at layout.testing2.actionPerformed(testing2.java:337) //This is the line I starred above
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)