Results 1 to 5 of 5
  1. #1
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default compiler error:"AWT-EventQueue-0" java.lang.NullPointerException at java.io.Reader.

    Hi

    I am stuck up with this error
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at java.io.Reader.<init>(Unknown Source)
            at java.io.InputStreamReader.<init>(Unknown Source)
            at View.read(View.java:146)
            at Assigning.assattr(Assigning.java:18)
            at Execute.actionPerformed(Execute.java:73)
            at javax.swing.AbstractButton.fireActionPerformed(Unknown 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.mouseReleased(Unknown Sour
    ce)
            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(Unknown Source)
            at java.awt.LightweightDispatcher.dispatchEvent(Unknown 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.pumpOneEventForFilters(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.run(Unknown Source)

    Here is the code snippet which is causing this error

    Java Code:
    public class View
    {
         public InputStreamReader read(String name)
        {
             ClassLoader loader = Viewplugin.class.getClassLoader();		
     	InputStream is=loader.getResourceAsStream("source/"+name);
    [B] InputStreamReader isr=new InputStreamReader(is);  //View.read(View.java:146)[/B]
     		return isr;
        }
    }
    Java Code:
    public class Assigning
    {
      View vi=new View();
      public String assattr(String filename,String nodestring)
    	{
    		String st1;		
    		[B]InputStreamReader attrfile=vi.read(filename);  //Assigning.assattr(Assigning.java:18)[/B]
    	     BufferedReader buff=new BufferedReader(attrfile);
    	     try {
    	 		//code here
    	 	   } catch (IOException e) {
    	 		// TODO Auto-generated catch block
    	 		e.printStackTrace();
    	 	  }	 
    		
    	 return somestring;
    	}
    }  
    }
    Java Code:
    public class Execute implements ActionListener {
    public void actionPerformed(ActionEvent e)
    	    {
              Assigning aa=new Assigning();
              for(String s:list)
              {
                  if(s.equals("one"))
                  {
                   String at1=aa.assattr("attr1.noa",s);
                  }
                  else if(s.equals("two"))
                  {
                    [B]String at2=aa.assattr("attr2.noa",s); //Execute.actionPerformed(Execute.java:73)[/B]
                  }
                  else
                  {
                     System.out.println("Not assigned");
                   }
              }
    }
    }
    can someone plz explain me what is causing this error??
    String at1=aa.assattr("attr1.noa",s);//this assignment works perfectly fine
    String at2=aa.assattr("attr2.noa",s); this is the line where it showing the error i am just changing the filename,the files are available they donot have any null values,i am not sure where i am gng wrong,if someone could point it out,it would be of great help

    Thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Try closing the BufferedReader before leaving the View assattr method:
    Java Code:
        ...
        BufferedReader buff=new BufferedReader(attrfile);
        try {
            //code here
            buff.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return somestring;
    }
    Do some debugging in the View read method:
    Java Code:
        ...
        System.out.println("is = " + loader.getResourceAsStream("source/"+name));
        InputStream is=loader.getResourceAsStream("source/"+name);
        InputStreamReader isr=new InputStreamReader(is);
        System.out.println("isr = " + isr);
        return isr;
    }

  3. #3
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default

    I tried with buff.close() but i get the same error..anyother suggestion plz

  4. #4
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default

    Thanks guys..its solved..

  5. #5
    itoldi is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default

    Hi Ms.Ranjan, could you please tell me how you had solved the problem above? I am stuck up with the eroor faolowing
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at java.io.Reader.<init>(Unknown Source)
    at java.io.InputStreamReader.<init>(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at ResourceTestFrame.<init>(ApletTest.java:37)
    at ApletTest$1.run(ApletTest.java:17)
    at java.awt.event.InvocationEvent.dispatch(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)

    the code snippet causing this error is:
    JTextArea textArea = new JTextArea();
    InputStream stream = getClass().getResourceAsStream("about.txt");
    Scanner in = new Scanner(stream); //(ApletTest.java:17)

Similar Threads

  1. Replies: 10
    Last Post: 05-11-2009, 12:56 PM
  2. Replies: 10
    Last Post: 01-29-2009, 09:00 AM
  3. Replies: 4
    Last Post: 10-09-2008, 07:08 PM
  4. Replies: 12
    Last Post: 10-05-2008, 07:52 AM
  5. Replies: 3
    Last Post: 01-29-2008, 02:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •