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.NullPointerException
at konta_bankowe.Interfejs.readFile(Interfejs.java)
at konta_bankowe.Interfejs.wyswietlHistorieRachunku(I nterfejs.java)
at konta_bankowe.Interfejs.access$0(Interfejs.java)
at konta_bankowe.Interfejs$1.actionPerformed(Interfej s.java)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown 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.mouseRe leased(Unknown Source)
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(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn 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.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)
and the code is
Expand|Select|Wrap|Line Numbers
- 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();
- }
- }