NullPointerException « error « Java I/O Q&A

1. NullPointerException Using JMockit to Test Mocked Twice

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

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

public class MockedFileTest extends TestCase
  @Mocked File file;

  public ...

2. Set.add() NullPointerException

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; 

public Set<String> getEmployees() throws FileNotFoundException {

3. Need help with NullPointerException

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.( at java.util.StringTokenizer.( at App3.( at App3.main( import*; 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.

I have complied 3 files (;; 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---------------------------------- import serial.*; import*; 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!

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*; import javax.swing.*; public class form extends javax.swing.JFrame { ObjectOutputStream Output; ObjectInputStream Input; File file = ...

6. NullPointerException problems

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

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

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

10. NullpointerException in getting files from vss

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; import*; import; import*; 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

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 ?

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!)

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);

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

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( at matrix.MatrixCalc$3.actionPerformed( at java.awt.MenuItem.processActionEvent( at java.awt.MenuItem.processEvent( at java.awt.MenuComponent.dispatchEventImpl( at java.awt.MenuComponent.dispatchEvent( at java.awt.EventQueue.dispatchEvent( at java.awt.EventDispatchThread.pumpOneEventForFilters( ...

16. java.lang.NullPointerException while Parsing a file

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

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