Hallo freunde;
ich bin mit BufferWriter nicht so flüssig. Ich will den openfile() methode mehrmals aufrufen. wenn ich BufferWriter auf null setze bekomme exception und wenn nicht bekomme ich fehler !! was mache ich falsch??
liebe Gruße
G
Exception ist :
ich bin mit BufferWriter nicht so flüssig. Ich will den openfile() methode mehrmals aufrufen. wenn ich BufferWriter auf null setze bekomme exception und wenn nicht bekomme ich fehler !! was mache ich falsch??
liebe Gruße
G
Code:
private static void outputChar(int i, int last, char c) throws IOException {
BufferedWriter bw = null;
for (int j = last; j < i; j++)
{
openfile(bw);
bw.write(c); -----> hier bricht das program
}
bw.close();
}
public static Object openfile(BufferedWriter bw) throws IOException {
File f1 = new File("c:/test1.txt");
FileWriter fw = new FileWriter(f1);
bw = new BufferedWriter(fw);
return bw;
}
Exception ist :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at suchAlgoritmus.outputChar(suchAlgoritmus.java:106)
at suchAlgoritmus.underline(suchAlgoritmus.java:94)
at suchAlgoritmus.auslesen(suchAlgoritmus.java:69)
at suchAlgoritmus.setFileName(suchAlgoritmus.java:25)
at Start$1.actionPerformed(Start.java:33)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)