473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

java.lang.NullPointerException

oll3i
679 512MB
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Zad21.Cennik.getCenna(Cennik.java)
at Zad21.KwiaciarniaView$1.actionPerformed(Kwiaciarni aView.java)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)



Expand|Select|Wrap|Line Numbers
  1. package Zad21;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. public class Cennik {
  7.      private static Cennik instance = null;
  8.      Map<String,Double> cennik = new HashMap<String,Double> ();
  9.  
  10.        private Cennik() {  // prywatny konstruktor
  11.        }
  12.  
  13.        public static Cennik getInstance() {
  14.           if(instance == null) {
  15.              instance = new Cennik();
  16.  
  17.           }
  18.           return instance;
  19.        }
  20.  
  21. public void setCennik(String nazwaKwiat,double cena){       
  22.     cennik.put(nazwaKwiat,cena);   
  23. }
  24.  
  25. public  Map<String,Double> getCennik(){ return cennik;}
  26.  
  27. public double getCenna(String nazwaKwiata){ return cennik.get(nazwaKwiata);}
  28. }
  29.  
  30.  

in some other class
Expand|Select|Wrap|Line Numbers
  1. m_add.addActionListener( new ActionListener() {
  2.     public void actionPerformed(ActionEvent e) {
  3.          Cennik c= Cennik.getInstance();
  4.  
  5.  
  6.          int a=Integer.parseInt(m_amount.getText());
  7.          table.addRow((String)kwiatyList.getSelectedItem(),a,c.getCenna((String)kwiatyList.getSelectedItem()));
  8.     }
  9.   });
  10.  
i want to get the value of selected item in combobox when a button is clicked
String)kwiatyList.getSelectedItem(), and when a user enters some input into JTextField then take the both values when a button is clicked and add the entries to a table
i get the nullpointerexception in c.getCenna((String)kwiatyList.getSelectedItem()));

thank u
Apr 4 '07 #1
1 1860
oll3i
679 512MB
i solved it thank u
Apr 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
2
by: Tim Murray | last post by:
First of all, I don't know much about Java, even its naming and version numbering nomenclature, and second, if there is a better group to ask this in, please let me know. System is Mac with...
3
sammyboy78
by: sammyboy78 | last post by:
Hello again, This time I'm creating a program that creates an array of CD objects and then displays the information. I've created a CD class, a CDInventory class and then a CDInventoryDisplay to...
0
by: gezkk | last post by:
hi, i m using http proxy service to get proxy and host to applet, its working fine with jdk1.5 but getting java.lang.NullPointerException in jdk1.6 And the following is mseeage contains java...
18
by: pradeep84 | last post by:
hi all, i'm using the following code and i'm getting exception in thread "main" java.lang.nullpointerexception at the line which is in bold. help me to solve this problem import...
0
by: ycinar | last post by:
hey all, i am working on a Java project using JBuilder.. when i build my code its fine, but when comes to run, it doesnt run and displays the following logs.. i think there is JDK conflict.. ...
1
by: ketand1 | last post by:
import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.sql.*; import java.lang.*; class DbAwt extends Frame implements ActionListener { private...
1
by: ksrashmi | last post by:
HI I am getting following exception when i use mxml tags in jsp <%@ taglib uri="FlexTagLib" prefix="mm" %> can any one tell why i am getting this exception type Exception report message...
3
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at...
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.