NullPointerException « error « Java I/O Q&A





1. NullPointerException Using JMockit to Test Mocked java.io.File Twice    stackoverflow.com

I'm getting a NullPointerException when I try to use a mocked File with JMockit:

package com.metamolecular.poobah.test;
import java.io.File;
import junit.framework.TestCase;
import mockit.Expectations;
import mockit.Mocked;

public class MockedFileTest extends TestCase
{
  @Mocked File file;

  public ...

2. Set.add() NullPointerException    stackoverflow.com

I'm am getting a NullPointerException while adding elements from a scanned file into a String set.

public class ChrisCorpManifests implements Manifests {  
Set<String> _employees; 

@Override
public Set<String> getEmployees() throws FileNotFoundException {
  ...

3. Need help with NullPointerException    coderanch.com

I get this error at the end of my code execution. Could anyone tell me why and how I fix it. java.lang.NullPointerException at java.util.StringTokenizer.(StringTokenizer.java:122) at java.util.StringTokenizer.(StringTokenizer.java:138) at App3.(App3.java:20) at App3.main(App3.java:42) import java.io.*; import java.util.*; public class App3 { public App3 ( ) throws IOException, NullPointerException { BufferedReader br = new BufferedReader(new FileReader(new File("data.txt"))); BufferedWriter out = new ...

4. Urgent!!!A NullPointerException !!! I can't solve it.    coderanch.com

I have complied 3 files (SerialBean.java;SerialBuffer.java;ReaderSerial.java) as my package successfully, it is named serial. The package extends javax.comm.*; I wanna do some serial work. Then I maked an application :SerialExample1 --------------------------------------code---------------------------------- ----------------------------SerialExmaple1.java----------------------------- import serial.*; import java.io.*; import javax.comm.*; public class SerialExample1 { public static void main(String args[]) { SerialBean sB=new SerialBean(1); sB.Initialize(); sB.WritePort("Hi,Chrono"); sB.ClosePort(); } } ----------------------------------------------------------------------------- It is good enough ...

5. Null Pointer Exception - Driving Me Mad!    coderanch.com

Hello im doing a Computer Science course and at the moment doing Java. I have this wierd problem where i can create a file, add stuff to it, but i cannot append (or read anymore!). Does anyone know whats wrong? Here's my work: ------------------------------------------------------------------------ import java.io.*; import javax.swing.*; public class form extends javax.swing.JFrame { ObjectOutputStream Output; ObjectInputStream Input; File file = ...

6. NullPointerException problems    coderanch.com

I have written a program in which I am using file I/O. I want to read to the end of the file. In the code snipped below I have read a line and am checking for null. System.out.println("INLINE: " + inLine); [B]if (inLine.equals(null))[/B] System.out.println("true"); else System.out.println("false"); As you can see I am printing the line before I check for null. It ...

7. How to solve NullpointerException    coderanch.com

hi, i hardly trying this using fileInputStream retrieve a xls file from particular directory like /var/www/html/sara/book1.xls i getting nullpointer exception problem: conn = DriverManager.getConnection("jdbc dbc river={Microsoft Excel Driver ( *.xls)};DBQ=" + dis);//file name i given has dis this only giving nullpointer exception please see my below code you will get full flow please see below code: File file = new File("/var/www/html/sara/book1.xls"); ...

8. passing in a file from the command line-----seeing a NullPointerException    coderanch.com

I'll take a deeper peek at the code, but I have some meetings today so I may not get to it until tomorrow. Any other takers while I sit in a conference room? By the way, it would be easier to track this thread if you posted replies rather than new topics as replies. That way we could scroll to view ...

9. File - NullPointerException    coderanch.com





10. NullpointerException in getting files from vss    coderanch.com

I want to get all files from vss under Library folder , but when i tried to run this i got NullpointerException. /jars used //ant_optional_1_4_1.jar //ant.jar package com.pdn; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.optional.vss.*; import org.apache.tools.ant.types.Path; import java.io.*; public class Pdn { public static void main(String args[]) { try { MSVSSGET vssGet=new MSVSSGET(); Project project = new Project(); project.setBaseDir(new File("C:\\Documents and Settings\\User\\Desktop\\PDN")); vssGet.setLogin("abc,abc"); ...

11. Unable to resolve Null Pointer Exception    coderanch.com

The solution would be to look at the stack trace, which tells you what line of code threw the exception. Then examine that code to see what variables are being dereferenced, and investigate which of them is null and what you can do about that. Posting the code with no further explanation is not a strategy which will get you anywhere. ...

12. Why do I get java.lang.NullPointerException only for a specific file ?    java-forums.org

Hi, I've a 74MB xml document and I've split it into 2 docs:52MB and 22MB respectively. I'm parsing the file using common Digester library, and everything works perfectly for the small file, but I get a NullPointerExceptio with the big one. I don't think the issue is the code because it works for the small file... I guess the problem is ...

13. NullPointerException: File Not Found (that clearly exists!)    forums.oracle.com

2. The code that calls (1) doesn't check for image == null so it gets an NPE if the file can't be found. If the method (1) had been declared to throw an IOException this problem wouldn't have arisen, as the compiler would have forced you to deal with the IOException somehow.

14. Null pointer exception during DocumentBuilder.parse(file);    forums.oracle.com

Hello All, I got null pointer exception while executing doc = builder.parse(xmlDataFile); There were few entities in the XML data file. On removing a particular entity, i was able to parse the file successfully The entity was some thing like this What could be the reason? Here is the code: DocumentBuilderFactory aFactory = DocumentBuilderFactory.newInstance(); aFactory.setValidating(false); ...

15. I cant save n' load Files, it Throws NullPointerException, help plz    forums.oracle.com

save.writeObject(matix); save.close(); } catch(IOException l){ aktual.setText("Fail 2 save Matrix"); } } Matix is a Matrix Object, Matrix object is 1 2D field, and 2 int, which set the fields lenght When I try to save it... it writes on Console: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at matrix.MatrixCalc.save_actionPerformed(MatrixCalc.java:335) at matrix.MatrixCalc$3.actionPerformed(MatrixCalc.java:86) at java.awt.MenuItem.processActionEvent(MenuItem.java:627) at java.awt.MenuItem.processEvent(MenuItem.java:586) at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:300) at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:288) at java.awt.EventQueue.dispatchEvent(EventQueue.java:602) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) ...

16. java.lang.NullPointerException while Parsing a file    forums.oracle.com

public class Server { //public static void main (String [] args ) throws IOException { public String getResponse () throws IOException { int filesize=500000; // file size long start = System.currentTimeMillis(); int bytesRead; int current = 0; // create socket ServerSocket servsock = new ServerSocket(45789); while (true) { System.out.println("Waiting for connection"); Socket sock = servsock.accept(); System.out.println("Connected : " + sock);





17. NullPointerException because of strange filename    forums.oracle.com

hi, I'm creating a tool that loops through all directories and that stores all the directorynames and filenames in a mysql database. but when looping through some dirs it fails with the following exception: Exception in thread "main" java.lang.NullPointerException when debugging I saw that it fails when a filename can not be read properly. for example on this filename a NullPointerException ...