compiler error:"AWT-EventQueue-0" java.lang.NullPointerException at java.io.Reader.
Hi
I am stuck up with this error
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
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;
}
}
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;
}
}
}
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