I am assigning my combobox to handle the Value or the Car Name so i make this code and NullPointerException is always the error does my code is wrong?
public CarRent()
{
initComponents();
setLocationRelativeTo(null);
try
{
AddItem();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void Conn() throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(conn1,user,pass);
}
public void AddItem() throws Exception
{
String s = "Select Car_Name from Car_Tbl";
rs = st.executeQuery(s);
while(rs.next())
{
System.out.println(cboCars);
cboCars.addItem(rs.getString("Car_Name"));
}
}
run: java.lang.NullPointerException at trypo.CarRent.AddItem(CarRent.java:77) at trypo.CarRent.(CarRent.java:50) at trypo.CarRent$4.run(CarRent.java:413) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745) at java.awt.EventQueue.access$300(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:706) at java.awt.EventQueue$3.run(EventQueue.java:704) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:715) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91) BUILD SUCCESSFUL (total time: 3 seconds)
cboCars? - Madhawa PriyashanthaSystem.out.println(cboCars);beforecboCars.addItem(rs.getString(1));and tell the output - Madhawa Priyashantha