nevermind the previous prob i posted
i m getting further and i get a new exception
in readFile method pleae help me with that one
thank u a lot in advance
java.lang.NullP ointerException
at konta_bankowe.I nterfejs.readFi le(Interfejs.ja va)
at konta_bankowe.I nterfejs.wyswie tlHistorieRachu nku(Interfejs.j ava)
at konta_bankowe.I nterfejs.access $0(Interfejs.ja va)
at konta_bankowe.I nterfejs$1.acti onPerformed(Int erfejs.java)
at javax.swing.Abs tractButton.fir eActionPerforme d(Unknown Source)
at javax.swing.Abs tractButton$Han dler.actionPerf ormed(Unknown Source)
at javax.swing.Def aultButtonModel .fireActionPerf ormed(Unknown Source)
at javax.swing.Def aultButtonModel .setPressed(Unk nown Source)
at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Unk nown Source)
at java.awt.Compon ent.processMous eEvent(Unknown Source)
at javax.swing.JCo mponent.process MouseEvent(Unkn own Source)
at java.awt.Compon ent.processEven t(Unknown Source)
at java.awt.Contai ner.processEven t(Unknown Source)
at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
at java.awt.Compon ent.dispatchEve nt(Unknown Source)
at java.awt.Lightw eightDispatcher .retargetMouseE vent(Unknown Source)
at java.awt.Lightw eightDispatcher .processMouseEv ent(Unknown Source)
at java.awt.Lightw eightDispatcher .dispatchEvent( Unknown Source)
at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
at java.awt.Window .dispatchEventI mpl(Unknown Source)
at java.awt.Compon ent.dispatchEve nt(Unknown Source)
at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
at java.awt.EventD ispatchThread.p umpOneEventForF ilters(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForFil ter(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.r un(Unknown Source)
and the code is
i m getting further and i get a new exception
in readFile method pleae help me with that one
thank u a lot in advance
java.lang.NullP ointerException
at konta_bankowe.I nterfejs.readFi le(Interfejs.ja va)
at konta_bankowe.I nterfejs.wyswie tlHistorieRachu nku(Interfejs.j ava)
at konta_bankowe.I nterfejs.access $0(Interfejs.ja va)
at konta_bankowe.I nterfejs$1.acti onPerformed(Int erfejs.java)
at javax.swing.Abs tractButton.fir eActionPerforme d(Unknown Source)
at javax.swing.Abs tractButton$Han dler.actionPerf ormed(Unknown Source)
at javax.swing.Def aultButtonModel .fireActionPerf ormed(Unknown Source)
at javax.swing.Def aultButtonModel .setPressed(Unk nown Source)
at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Unk nown Source)
at java.awt.Compon ent.processMous eEvent(Unknown Source)
at javax.swing.JCo mponent.process MouseEvent(Unkn own Source)
at java.awt.Compon ent.processEven t(Unknown Source)
at java.awt.Contai ner.processEven t(Unknown Source)
at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
at java.awt.Compon ent.dispatchEve nt(Unknown Source)
at java.awt.Lightw eightDispatcher .retargetMouseE vent(Unknown Source)
at java.awt.Lightw eightDispatcher .processMouseEv ent(Unknown Source)
at java.awt.Lightw eightDispatcher .dispatchEvent( Unknown Source)
at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
at java.awt.Window .dispatchEventI mpl(Unknown Source)
at java.awt.Compon ent.dispatchEve nt(Unknown Source)
at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
at java.awt.EventD ispatchThread.p umpOneEventForF ilters(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForFil ter(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.r un(Unknown Source)
and the code is
Code:
package konta_bankowe;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.NumberFormat;
import javax.swing.*;
import static java.awt.Color.*;
import static java.lang.Thread.sleep;
import static java.lang.System.out;
public class Interfejs extends JFrame {
JTextArea report = new JTextArea(25, 40);
public Interfejs() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setTitle("Program kont bankowych(Katarzyna Olbromska).");
JPanel panel = new JPanel();
JLabel label = new JLabel("Podaj Number konta :");
final JTextField numer_konta_field = new JTextField();
numer_konta_field.setColumns(10);
panel.add(label);
panel.add(numer_konta_field);
JButton button = new JButton();
button.setLabel("Szukaj");
button.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
wyswietlHistorieRachunku(numer_konta_field.getText());
}
});
panel.add(button);
getContentPane().add(panel, BorderLayout.SOUTH);
pack();
report.setBorder(BorderFactory.createTitledBorder("Raport z kont"));
add(new JScrollPane(report));
JPanel p = new JPanel();
final JLabel lab = new JLabel("Konta");
lab.setOpaque(true);
p.add(lab);
final JButton b1 = new JButton("Złote");
setColor(YELLOW, b1);
b1.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
p.add(b1);
final JButton b2 = new JButton("Srebrne");
Color c1 = new Color(213, 213, 213);
//g.setColor(c);
setColor(c1, b2);
b2.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
p.add(b2);
final JButton b3 = new JButton("Brązowe");
Color c2 = new Color(144, 124, 72);
//g.setColor(c);
setColor(c2, b3);
b3.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
p.add(b3);
final JButton b4 = new JButton("Normalne");
setColor(WHITE, b4);
b3.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
p.add(b4);
add(p, "North");
pack();
setVisible(true);
}
private void setColor(final Color color, final Component ... comps) {
for (Component c : comps) c.setBackground(color);
}
private void wyswietlHistorieRachunku(String numer_konta) {
report.setText(" ");
//report.append("Numer konta: " +numer_konta +'\n');
report.append("Historia Rachunku: " +'\n');
readFile(numer_konta);
}
private void readFile(String numer_konta){
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("konta//"+numer_konta+".txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String[] historia = null;
int n=0;
while((strLine = br.readLine()) != null) {
historia[n]=strLine;
System.out.println("historia[n]="+historia[n]+"strLine="+strLine);
n++;
}
for (String h : historia)
report.append(h +'\n');
in.close();
}catch (FileNotFoundException e) {
System.err.println("Nie ma takiego konta(File not found!)");
}catch (IOException e) {
System.err.println(e);
}catch (Exception ex) {
ex.printStackTrace(); }
}
}
package konta_bankowe;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Konto {
/**
* @param args
*/
protected double sr_dost;
private String NumerKonta;
public Konto()
{ new Interfejs();}
public void depozyt( double amount )
{
sr_dost += amount;
}
public double wyplata( double amount )
{
// See if amount can be withdrawn
if (sr_dost >= amount)
{
sr_dost -= amount;
return amount;
}
else
// Withdrawal not allowed
return 0.0;
}
public double get_sr_dost()
{
return sr_dost;
}
public static void main(String[] args)throws IOException {
Konto konto = new Konto();
}
}
Comment