473,569 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java.lang.NullP ointerException

oll3i
679 Contributor
Exception in thread "AWT-EventQueue-0" java.lang.NullP ointerException
at Zad21.Cennik.ge tCenna(Cennik.j ava)
at Zad21.Kwiaciarn iaView$1.action Performed(Kwiac iarniaView.java )
at javax.swing.Abs tractButton.fir eActionPerforme d(Unknown Source)
at javax.swing.Abs tractButton$Han dler.actionPerf ormed(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)kwiatyLi st.getSelectedI tem(), 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 nullpointerexce ption in c.getCenna((Str ing)kwiatyList. getSelectedItem ()));

thank u
Apr 4 '07 #1
1 1886
oll3i
679 Contributor
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
3094
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 Transformer convert that via XSLT to valid XSL-FO. So I define a SAXReader which fires the SAX Events for the Java Object. This works fine and the...
2
13509
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 10.4.4. I have Java 1.3.1 and 1.4.2 plug-ins, and J2SE 5.0 (1.5.0) installed. The Java preferences application lets me choose J2SE 5 or 1.4.2 to run...
3
3577
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 use the previos two. I've gotten all of this code oto compile but I'm still doing something wrong. I'm about to pull my hair out! When I run my...
0
1565
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 console java.lang.NullPointerException at...
18
2566
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 java.applet.*; import java.awt.*; import java.io.*; import javax.swing.*; import java.sql.*;
0
1633
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.. actually when i build it, it creates a jar file which is totally fine (i can confirm that because i use that jar file in another project) any idea on...
1
2407
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 TextField t1, t2, t3;
1
2408
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 description The server encountered an internal error () that prevented it from fulfilling this request.
3
7640
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 sortmergejoin.MergeJoin.Field(MergeJoin.java:204) at sortmergejoin.MergeJoin.SMJoin(MergeJoin.java:84) at...
1
6741
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 "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1041) at java.awt.Container.add(Container.java:365) ...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.