Exception in thread "main" java.lang.NullPointerException:....Suggestions?

Exception in thread "main" java.lang.NullPointerException: Canvas3D: null GraphicsConfiguration
at javax.media.j3d.Canvas3D.checkForValidGraphicsConfig(Canvas3D.java:963)
at javax.media.j3d.Canvas3D.<init>(Canvas3D.java:1006)
at HelloJava3Da.<init>(HelloJava3Da.java:16)
at HelloJava3Da.main(HelloJava3Da.java:45)

Hello, Can you paste your code here?
I think you may miss the following
        GraphicsConfiguration config =
           SimpleUniverse.getPreferredConfiguration();
        Canvas3D canvas3D = new Canvas3D(config);Thanks & Regards
<~ChaosCrisis~>

Similar Messages

  • Exception in thread "main" java.lang.NullPointerException

    hi
    I am new to Java, and taking an introductory course in java. I wrote the code given bellow and get following error "C:\java\assingment2>java test123
    Exception in thread "main" java.lang.NullPointerException
    at PartCatalog.Add(test123.java:56)
    at test123.main(test123.java:102)"
    Can any body help me please
    import java.util.*;
    class PartRecord
    public String PartName;
    public String PartNumber;
    public float Cost;
    public int Quantity;
    public static int counter ;
    public PartRecord()
    { PartName ="";
         PartNumber="";
    Cost = 0;
         Quantity = 0;
         counter = 0;
    public void Set(String name, final String num,
    float cost, int quantity)
         PartName = name;
    PartNumber= num;
    Cost = cost;
    Quantity = quantity;
    counter++;
    public float Get()
                   return Cost*Quantity;
    public static int Counter() {return counter;}
    class PartCatalog
    public PartCatalog()
    npart=0;
    public void Add(String name, String num,
    float cost, int quantity)
    if(npart>=1000) return;
    Parts[npart++].Set(name,num,cost,quantity);
    public float ShowInventory()
    int inventory = 0;
    for(int i=0; i<npart; i++)
    inventory+= Parts.Get();
    return inventory;
    public PartRecord[] Parts = new PartRecord[1000];
    public int npart;
    class ExtPartCatalog extends PartCatalog
    public void Sort()
    Arrays.sort(Parts);
    public void Print()
    for(int i=0; i<npart; i++)
    System.out.println ( Parts[i].PartName + "\t "
    + Parts[i].PartNumber + "\t "
    + Parts[i].Cost + "\t "
    + Parts[i].Quantity + "\n");
    class test123{
    public static void main(String args[])          
         ExtPartCatalog catalog = new ExtPartCatalog();
         catalog.Add("tire ", "1", 45, 200);
         catalog.Add("microwave", "2", 95, 10);
         catalog.Add("CD Player", "3", 215, 11);
         catalog.Add("Chair ", "4", 65, 10);
         catalog.Sort();
    catalog.Print();
    System.out.println("Inventory is " + catalog.ShowInventory());
    ExtPartCatalog catalog2 = new ExtPartCatalog();
    catalog2.Add("ttt ", "1", 45, 200);
    System.out.print("\n\nTotally there are " + PartRecord.Counter() );
    System.out.println(" Parts being set" );

    Thank you for your reply. I think i used
    public PartRecord[] Parts = new PartRecord[1000];
    so i have created the reference. I tries what you told me but it still did not work. I am putting the code again, but now in the formatted form so that you can read it more easily. I will appreciate your help. Thanks
    <code>
    import java.util.*;
    class PartRecord
    {      public String PartName;
    public String PartNumber;
    public float Cost;
    public int Quantity;
    public static int counter ;
         public PartRecord()
              PartName ="";
              PartNumber="";
              Cost = 0;
              Quantity = 0;
              //counter = 0;
         public void Set(String name, final String num,
    float cost, int quantity)
         PartName = name;
         PartNumber= num;
         Cost = cost;
         Quantity = quantity;
         counter++;
         public float Get()
         return Cost*Quantity;
         public static int Counter() {return counter;}
    class PartCatalog
    {      public PartRecord[] Parts = new PartRecord[1000];
         public int npart;
    public PartCatalog()
    npart=0;
         public void Add(String name, String num,
         float cost, int quantity)
         if(npart>=1000) return;
         Parts[npart++].Set(name,num,cost,quantity);
         public float ShowInventory()
              float inventory = 0;
              for(int i=0; i<npart; i++)
              inventory= Parts[npart].Get();
              return inventory;
    /*class ExtPartCatalog extends PartCatalog
         public void Sort()
         Arrays.sort(Parts);
         public void Print()
                   for(int i=0; i<npart; i++)
                   System.out.println ( Parts.PartName + "\t "
                                  + Parts[i].PartNumber + "\t "
                                  + Parts[i].Cost + "\t "
                             + Parts[i].Quantity + "\n");
    class azimi_a{
    public static void main(String args[])
    PartCatalog c = new PartCatalog() ;//= new PartCatalog[4];
    c.Add("tire ", "1", 45, 200);
    c.Add("microwave", "2", 95, 10);
    c.Add("CD Player", "3", 215, 11);
    c.Add("Chair ", "4", 65, 10);
    <code>

  • Problem about "Exception in thread "main" java.lang.NullPointerException"

    This is t error message once i run the file
    Exception in thread "main" java.lang.NullPointerException
    at sendInterface.<init>(sendInterface.java:64)
    at sendInterface.main(sendInterface.java:133)
    * @(#)sendInterface.java
    * @author
    * @version 1.00 2008/7/18
    import java.awt.BorderLayout;
    import java.awt.Image;
    import java.awt.GridLayout;
    import java.awt.Panel;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultListModel;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JRadioButton;
    import javax.swing.JScrollPane;
    import javax.swing.ListModel;
    import javax.swing.UIManager;
    import javax.swing.SwingConstants;
    import java.io.*;
    import java.sql.*;
    import java.net.*;
    public class sendInterface  /*implements ActionListener*/{
         JFrame frame = new JFrame();
         private Panel topPanel;
         private Panel sendMessagePanel;
         private Panel sendFilePanel;
         private JLabel senderID;
         private JLabel receiverID;
         private JLabel senderDisplay;
         private DefaultListModel receiverListModel = new DefaultListModel();
         private JList receiverID_lst = new JList(receiverListModel);
         private JRadioButton sendType;
         String userName;
         String[] userList = null ;
         int i=0;
         Connection con;     
        public sendInterface() {
             String ListName;
                 try
                     JFrame.setDefaultLookAndFeelDecorated( true );
              catch (Exception e)
               System.err.println( "Look and feel not set." );
           frame.setTitle( "Send Interface" );
             topPanel.setLayout( new GridLayout( 2 , 1 ) );                          //line 64*************************
             senderID = new JLabel( "Sender:", SwingConstants.LEFT );
             senderDisplay = new JLabel( "'+...+'", SwingConstants.LEFT );
             receiverID = new JLabel( "Receiver:", SwingConstants.LEFT);
    //         receiverID_lst = new JList( ListName );
              frame.add(senderID);
             frame.add(senderDisplay);
             frame.add(receiverID);
    //         frame.add(receiverListModel);
             frame.add(new JScrollPane(receiverID_lst), BorderLayout.CENTER);
             frame.setLocation(200, 200);
             frame.setSize(250, 90);
             frame.setVisible(true);
        public void setListName(String user)
             try{
                  userName = user;
                  Class.forName("com.mysql.jdbc.Driver");
                   String url = "jdbc:mysql://localhost:3306/thesis";
                   con = DriverManager.getConnection(url, "root", "");
                   Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
                   ResultSet rs = stmt.executeQuery("select * from user where User_ID!= '" + userName + "'");
                   System.out.println("Display all results:");
                   while(rs.next()){
                      String user_id = rs.getString("User_ID");
                      System.out.println("\tuser_id= " + user_id );
         //             receiverListModel.addElement(user_id);
                        userList=user_id;
                        i++;
              }//end while loop
              receiverListModel.addElement(userList);
         catch(Exception ex)
    ex.printStackTrace();
         finally
    if (con != null)
    try
    con.close ();
    System.out.println ("Database connection terminated");
    catch (Exception e) { /* ignore close errors */ }
    public String getUserName()
         return userName;
    public String[] getUserList()
         return userList;
    public static void main(String[] args) {
    new sendInterface(); //line 133******************************************
    thank ur reply:D
    Edited by: ocibala on Aug 3, 2008 9:54 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    And where do you instantiate topPanel before you invoke setLayout?
    db

  • Help with Exception in thread "main" java.lang.NullPointerException

    I got this exception while running the code in Netbeans IDE 6.1. The code is compiling fine...Please tell me what the problem is
    Exception in thread "main" java.lang.NullPointerException
    at Softwareguide.chooseanswer(Softwareguide.java:32)
    at Driver.main(Driver.java:7)
    public class Driver
        public static void main(String[] args)
            Softwareguide swguide = new Softwareguide();
            swguide.chooseanswer();
    public class Softwareguide
        State test1;
        State test2;
        State test3;
        State test4;
        State test5;
        State subtest1;
        State subtest2;
        State subtest3;
        State subtest4;
        State subtest5;
        State state = test1;
        public Softwareguide()
            test1 = new Test1(this);
            test2 = new Test2(this);
            test3 = new Test3(this);
            test4 = new Test4(this);
            test5 = new Test5(this);
            subtest1 = new SubTest1(this);
            subtest2 = new SubTest2(this);
            subtest3 = new SubTest3(this);
            subtest4 = new SubTest4(this);
            subtest5 = new SubTest5(this);
        public void chooseanswer()
            state.chooseanswer();
       /* public void chooseyes()
            state.chooseyes();
        public void chooseno()
            state.chooseno();
        public State getState()
            return state;
        void setState(State state)
         this.state = state;
        public State getTest1State()
            return test1;
        public State getTest2State()
            return test2;
        public State getTest3State()
            return test3;
        public State getTest4State()
            return test4;
        public State getTest5State()
            return test5;
        public State getsubTest1State()
            return subtest1;
        public State getsubTest2State()
            return subtest2;
        public State getsubTest3State()
            return subtest3;
        public State getsubTest4State()
            return subtest4;
        public State getsubTest5State()
            return subtest5;
        public String toString()
            StringBuffer result = new StringBuffer();
            result.append("\n Starting Diagnostic Test...");
            return result.toString();
    }

    spiderjava wrote:
    the variable state is assigned to test1. This variable(test1) is not initialized anywhere.It is initialized in the c'tor. Which is invoked after the "global" object and attribute initialization. So it is there, but comes too late.
    You should definitly not write a technical Java blog and post it all over the place.

  • Exception in thread "main" java.lang.NullPointerException error JDeveloper 12c

    Hello,
    I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
    I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
    I have a table "Beer" and I want to select all the data out with a stored procedure which I call out of Java app.
    I have a java.class file Store_A.java which I have loaded into the ORACLE database with LOADJAVA :
        import java.sql.*;
        import java.io.*;
        public class Store_a {
          public static void apskatit ()
            throws SQLException
            { String sql =
              "SELECT * FROM Beer";
            try { Connection conn = DriverManager.getConnection("jdbc:default:connection:");
              PreparedStatement pstmt = conn.prepareStatement(sql);
              ResultSet rset = pstmt.executeQuery();
              rset.close();
              pstmt.close();
            catch (SQLException e) {System.err.println(e.getMessage());
    Then I have created a procedure which I plan to call out in java:
        CREATE OR REPLACE PACKAGE Store_a AS
        PROCEDURE apskatit;
        END Store_a;
        CREATE OR REPLACE PACKAGE BODY Store_a AS
        PROCEDURE apskatit AS LANGUAGE JAVA
        NAME 'Store_a.apskatit()';
        END Store_a;
    And I have a java file that I have created with JDeveloper 12c:
        import java.sql.Connection;
        import java.sql.DriverManager;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        public class Class1 {
             * @param args
            public static void main(String[] args) throws SQLException {
                Connection conn = null;
                try {
                    Class.forName("oracle.jdbc.driver.OracleDriver");
                    //Izveidojam savienojumu
                    conn = DriverManager.getConnection("jdbc.oracle.thin:@localhost:1521", "SYSTEM", "asdasd");
                    // Izveidojam callable statement
                    CallableStatement stmt = conn.prepareCall("CALL Store_a.apskatit()");
                    ResultSet resul = stmt.executeQuery();
                    while (resul.next()) {
                        System.out.println(resul.getInt(1) + "\t" + resul.getString(2));
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
    When I try to run the java file, I get this error "Exception in thread "main" java.lang.NullPointerException at client.Class1.main(Class1.java:29).
    So the line I get error in is "conn.close();"
    How to fix this?
    Thank you very much in advance.

    I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
    I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
    Maybe you haven't read it yet but I told you in your other thread what you were doing wrong and, step by step, how to address the problem.
    https://forums.oracle.com/thread/2611124
    I'm not going to repeat everything again just this one main piece of advice:
    Until you get you code working outside the database don't even bother trying to load it into the DB and create a Java stored procedure.
    You are trying to deal with too many different issues at the same time. Unless you solve your primary Java problem by fixing the code outside the DB you will have nothing but problems loading it into the DB.
    And just get rid of this line of code - you don't need it anymore and it hasn't been done like that for many years now:
    Class.forName("oracle.jdbc.driver.OracleDriver");

  • Re: Exception in thread "main" java.lang.NullPointerException

    Hi
    I am getting the following error. I cannot see any uninitialised objects. I have spent enough time on it .Could someone help me with this.
    Thanks in advance
    Exception in thread "main" java.lang.NullPointerException
            at pointlist.pointList.add(pointList.java:31)
            at pointlist.pointList.main(pointList.java:67)
            at pointlist.pointList.add(pointList.java:31)
            at pointlist.pointList.main(pointList.java:67)
    package pointlist;
    import javax.vecmath.Point2d;
    public class pointList extends Point2d{
        protected transient int size = 0;
        protected Point2d[] pointList = new Point2d[10];
        public pointList(){       
        public void add(int x,int y){
            if(pointList.length == size)
                resize(pointList.length * 2);
                System.out.print(size+"\n");
            pointList[size].setX(x);
            pointList[size].setY(y);       
            System.out.print(x+"\n"+y);       
            size++;
            System.out.print("\n"+size);
        public int size(){
            if(size <= 0)
            return(0);
            else
            return(size-1);
        private void resize(int newsize){
            Point2d[] newpointList = new Point2d[newsize]; // Create a new array
        public int[] get(int index){
            if(index>size)
                      throw new ArrayIndexOutOfBoundsException(index);
            else
                int[] point = new int[2];
                point[0] = (int)pointList[index-1].x;
                point[1] = (int)pointList[index-1].y;
                return(point);
    public static void main(String args[]){
        pointList plist = new pointList();
        plist.add(10, 10);
    }

    An Object-array (or in your case an array of Point2D) is just an array of references in Java.
    With "new Point2D[10]" you've created an array capable of holding 10 references to Point2D objects, but you've not yet created an Point2D object (each of those references is null). You'll need to create such a Point2D object in your add() method (before you try to call setX() and setY() on it).
    Two additional hints:
    * Your class should really be called PointList, because class names should start with a upper-case letter in Java
    * your resize method doesn't keep the old values, but simply creates a new (empty) array.

  • Need help with Exception in thread "main" java.lang.NullPointerException

    here is the error
    Exception in thread "main" java.lang.NullPointerException
    at stream.createFrame(stream.java:153)
    at chat.createMessage(chat.java:14)
    this is where the error is in stream
    public void createFrame(int id) {
              *buffer[currentOffset++] = (byte)(id + packetEncryption.getNextKey());*
    and this is where it comes from in chat
    outStream.createFrame(85);                    
    i just cant see whats causeing the exception

    spiderjava wrote:
    the variable state is assigned to test1. This variable(test1) is not initialized anywhere.It is initialized in the c'tor. Which is invoked after the "global" object and attribute initialization. So it is there, but comes too late.
    You should definitly not write a technical Java blog and post it all over the place.

  • Help with arrays and Exception in thread "main" java.lang.NullPointerExcept

    Hi, I have been having trouble all day getting this array sorted and put into a new array. I think it is something simple with my nested loops in sortCityArray() that is causing the problem. Any help would be greatly appreciated. The error is thrown on line 99 at Highway.sortCityArray(Highway.java:99)
    import java.util.Scanner;
    import java.io.*;
    import java.util.Arrays;
    public class Highway
    private String[] listOfCities=new String[200];
    private City[] cityArray=new City[200];
    private City[] sortedCityArray=new City[200];
    private String city="";
    private String city2="";
    private String fileName;
    private City x;
    private int milesToNextCity;
    private int milesAroundNextCity;
    private int speedToNextCity;
    public Highway(String filename)
    String fileName=filename;//"I-40cities.txt";
           File myFile = new File(fileName);
           try {
           Scanner scan=new Scanner(myFile);
           for(int i=0; scan.hasNextLine(); i++){
           String city=scan.nextLine();
           String city2=scan.nextLine();
           int milesToNextCity=scan.nextInt();
           int milesAroundNextCity=scan.nextInt();
           int speedToNextCity=scan.nextInt();
                   if(scan.hasNextLine()){
              scan.nextLine();
           cityArray=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
    // System.out.println(cityArray[i].getCity());
    // System.out.println(cityArray[i].getNextCity());
    // System.out.println(cityArray[i].getLengthAB());
    // System.out.println(cityArray[i].getLengthAroundB());
    // System.out.println(cityArray[i].getSpeedAB());
    catch (Exception e) {
    System.out.println(e);
    //return cityArray;
    /*public City[] doCityArray(){
    File myFile = new File(fileName);
    try {
    Scanner scan=new Scanner(myFile);
    for(int i=0; scan.hasNextLine(); i++){
    String city=scan.nextLine();
    String city2=scan.nextLine();
    int milesToNextCity=scan.nextInt();
    int milesAroundNextCity=scan.nextInt();
    int speedToNextCity=scan.nextInt();
         if(scan.hasNextLine()){
              scan.nextLine();
    cityArray[i]=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
    // System.out.println(cityArray[i].getCity());
    // System.out.println(cityArray[i].getNextCity());
    // System.out.println(cityArray[i].getLengthAB());
    // System.out.println(cityArray[i].getLengthAroundB());
    // System.out.println(cityArray[i].getSpeedAB());
    catch (Exception e) {
    System.out.println(e);
    return cityArray;
    public City[] sortCityArray(){
    sortedCityArray[0]=new City(cityArray[0].getCity(),cityArray[0].getNextCity(),cityArray[0].getLengthAB(),cityArray[0].getLengthAroundB(),cityArray[0].getSpeedAB());
    for(int j=0; j<cityArray.length; j++ )
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
              break;
    /*     for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
    //     j++;
    System.out.println(sortedCityArray[0].getCity());
    System.out.println(sortedCityArray[0].getNextCity());
    System.out.println(sortedCityArray[0].getLengthAB());
    System.out.println(sortedCityArray[0].getLengthAroundB());
    System.out.println(sortedCityArray[0].getSpeedAB());
    System.out.println(sortedCityArray[1].getCity());
    System.out.println(sortedCityArray[1].getNextCity());
    System.out.println(sortedCityArray[1].getLengthAB());
    System.out.println(sortedCityArray[1].getLengthAroundB());
    System.out.println(sortedCityArray[1].getSpeedAB());
    System.out.println(sortedCityArray[2].getCity());
    System.out.println(sortedCityArray[2].getNextCity());
    System.out.println(sortedCityArray[2].getLengthAB());
    System.out.println(sortedCityArray[2].getLengthAroundB());
    System.out.println(sortedCityArray[2].getSpeedAB());
    System.out.println(sortedCityArray[3].getCity());
    System.out.println(sortedCityArray[3].getNextCity());
    System.out.println(sortedCityArray[3].getLengthAB());
    System.out.println(sortedCityArray[3].getLengthAroundB());
    System.out.println(sortedCityArray[3].getSpeedAB());
    System.out.println(sortedCityArray[4].getCity());
    System.out.println(sortedCityArray[4].getNextCity());
    System.out.println(sortedCityArray[4].getLengthAB());
    System.out.println(sortedCityArray[4].getLengthAroundB());
    System.out.println(sortedCityArray[4].getSpeedAB());
    return cityArray;
    /*public String[] listOfCities(){
    File myFile = new File("I-40cities.txt");
    try {
    Scanner scan=new Scanner(myFile);
    for(int i=0; scan.hasNextLine(); i++){
         String city=scan.nextLine();
         city=city.trim();
    scan.nextLine();
    scan.nextLine();
         listOfCities[i]=city;
         System.out.println(listOfCities[i]);
    catch (Exception e) {
    System.out.println(e);
    return listOfCities;
    public static void main(String args[]) {
    Highway h = new Highway("out-of-order.txt");
    h.sortCityArray();

    the ouput is perfect according to the print lines if I use (increase the int where j is in the loop manually by one) :
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[0].getNextCity().equals(cityArray.getCity())){
              sortedCityArray[0+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
              break;
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[1].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[1+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[2].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[2+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[3].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[3+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
    But I cant do this for 200 elements. Are the loops nested right?
    Edited by: modplan on Sep 22, 2008 6:49 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Exception in thread "main" java.lang.ExceptionInInitializerError

    Exception in thread "main" java.lang.ExceptionInInitializerError
    at platinum.logger.XAbstractLogger.setStreams(XAbstractLogger.java:44)
    at platinum.logger.XConsoleLogger.initStreams(XConsoleLogger.java:32)
    at platinum.logger.XConsoleLogger.<init>(XConsoleLogger.java:27)
    at platinum.platinum.main(platinum.java:55)
    Caused by: java.lang.NullPointerException
    at platinum.util.XResourceManager.initResourceBundle(XResourceManager.java:34)
    at platinum.XRepository.<clinit>(XRepository.java:109)
    ... 4 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    I get a msg like this wen i try to run my project.
    The code which gives the error is:
    import java.io.*;
    import java.util.*;
    import platinum.*;
    public abstract class XAbstractLogger implements XLogger
         public XAbstractLogger()
              this(XProjectConstants.LOG_MODE_VERBOSE);
         public XAbstractLogger(int log_mode)
              setLogMode( new XLogMode(log_mode) );
         protected void setStreams(PrintStream ps_out, PrintStream ps_err) throws IOException,Exception
              out = ps_out;
              err = ps_err;
              // Log some stuff
         String[] props = {
                   "java.version", "java.vendor", "java.compiler", "os.name",
                   "os.version", "os.arch", "user.home"
              if( !logMode.isOff() )
                   logImpl(XRepository.getLogger(), "When reporting bugs, please include the following information:", MESSAGE, out);
                   logImpl(XRepository.getLogger(), XProjectConstants.PRODUCT_NAME+" version="+XProjectConstants.PRODUCT_VERSION, MESSAGE, out);
                   for( int i=0; i<props.length; i++)
                        logImpl(XRepository.getLogger(), props[i] + "=" + System.getProperty(props), MESSAGE, out);
         public void setLogMode(XLogMode log_mode)
              logMode = log_mode;
         public void addLogException(String log_e, XLogMode log_mode)
              if( !logExceptions_Modes.containsKey(log_e) )
                   logExceptions_Modes.put(log_e, log_mode);
         public void removeLogException(String log_e)
              logExceptions_Modes.remove(log_e);
         public final void message(Object src, Object obj)
              if( logMode.getLogMessages() )
                   logImpl(src, obj, MESSAGE, out);
         public final void debug(Object src, Object obj)
              if( logMode.getLogDebugs() )
                   logImpl(src, obj, DEBUG, out);
         public final void warning(Object src, Object obj)
              if( logMode.getLogWarnings() )
                   logImpl(src, obj, WARNING, err);
         public final void error(Object src, Object obj)
              if( logMode.getLogErrors() )
                   logImpl(src, obj, ERROR, err);
         private void logImpl(Object src, Object obj, int type, PrintStream ps)
              if( ps==null )
                   return;
         String class_name = XRepository.getResourceManager().getClassName(src);
              if( isAnException(class_name, type) )
                   return;
              ps.print("["+getTitle(type)+"-"+class_name+"] ");
              if( obj instanceof Throwable )
                   ((Throwable)obj).printStackTrace(ps);
              else
                   ps.println(obj);
         private boolean isAnException(String str, int type)
         Iterator it = logExceptions_Modes.keySet().iterator();
         String excep_item;
         XLogMode log_mode;
              while( it.hasNext() )
                   excep_item = (String)it.next();
                   log_mode = (XLogMode)logExceptions_Modes.get(excep_item);
                   if( excep_item.equalsIgnoreCase(str) )
                        if( ((type==MESSAGE) && (log_mode.getLogMessages()==false)) ||
                             ((type==DEBUG) && (log_mode.getLogDebugs()==false)) ||
                             ((type==WARNING) && (log_mode.getLogWarnings()==false)) ||
                             ((type==ERROR) && (log_mode.getLogErrors()==false)) )
                        return true;
              return false;
         private String getTitle(int type)
              switch( type )
                   case MESSAGE:
                        return ">Message:";
                   case DEBUG:
                        return ">Debug:";
                   case WARNING:
                        return ">Warning:";
                   case ERROR:
                        return ">Error:";
                   default:
                        return ">??!!";
    // Attributes:
         private static final int MESSAGE = 1;
         private static final int DEBUG = 3;
         private static final int WARNING = 5;
         private static final int ERROR = 7;
         private PrintStream out = null;
         private PrintStream err = null;
         private Map logExceptions_Modes = new HashMap();
         private XLogMode logMode = new XLogMode();

    The code which gives the error is:You have read the stack trace incorrectly and posted the wrong code.... read the trace again:
    at platinum.platinum.main(platinum.java:55)
    Caused by: java.lang.NullPointerException
    at platinum.util.XResourceManager.initResourceBundle(XResourceManager.java:34)
    at platinum.XRepository.<clinit>(XRepository.java:109) Something is throwing null pointer exception in *'platinum.util.XResourceManager.initResourceBundle'* method.
    Thanks!

  • Exception in thread "main" java.lang.NoSuchMethodError?

    This is the exact same error I recieved from running ListGames:
    Exception in thread "main" java.lang.NoSuchMethodError: ListGames.getConnection(Ljava/lang/String;)Ljava/sql/Connection;
    at ListGames.getGames(ListGames.java:21)
    at ListGames.main(ListGames.java:7)
    What's wrong?
    ListGames.java:
    import java.sql.*;
    import java.text.NumberFormat;
    import ...util.MysqlConnection; // purposely incomplete
    public class ListGames {
         static Connection conn = MysqlConnection.openMysqlConnection("ds_games");
         public static void main(String args[]) {
              NumberFormat cf = NumberFormat.getCurrencyInstance();
              ResultSet games = getGames();
              try {
                   while (games.next()) {
                        Game g = getGame(games);
                        String msg = Integer.toString(g.year) + ": " + g.title + " (" + cf.format(g.price) + ")";
                        System.out.println(msg);
              } catch (SQLException e) {
                   e.printStackTrace();
                   conn = MysqlConnection.closeMysqlConnection(conn);
         private static ResultSet getGames() {          
              try {
                   Statement s = conn.createStatement();
                   ResultSet rows = s.executeQuery("select title, year, price from my_ds_games order by year, price, title");
                   return rows;
              } catch (SQLException e) {
                   e.printStackTrace();
                   conn = MysqlConnection.closeMysqlConnection(conn);
              return null;
         private static Game getGame(ResultSet games) {
              try {
                   String title = games.getString("Title");
                   int year = games.getInt("Year");
                   double price = games.getDouble("Price");
                   return new Game(title, year, price);
              } catch (SQLException e) {
                   e.printStackTrace();
                   conn = MysqlConnection.closeMysqlConnection(conn);
              return null;
         private static class Game {
              public String title;
              public int year;
              public double price;
              public Game(String title, int year, double price) {
                   this.title = title;
                   this.year = year;
                   this.price = price;
    MysqlConnection.java:
    package ...util; // purposely incomplete
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public final class MysqlConnection {     
         public static final Connection openMysqlConnection(String database) {
              Connection conn = null;
              try {
                   Class.forName("com.mysql.jdbc.Driver");
                   conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + database, user, password); // username and password purposely uninitialized
              } catch(SQLException e) {
                   System.out.println("SQLException: " + e.getMessage());
                   System.out.println("SQLState: " + e.getSQLState());
                   System.out.println("VendorError: " + e.getErrorCode());
              } catch(Exception e) {
                   e.printStackTrace();
              } finally {
                   return conn;
         public static final Connection closeMysqlConnection(Connection conn) {
              try {
                   if (conn != null) {
                        conn.close();
                        if (conn == null) {
                             System.out.println("Conection Closed");
              } catch (SQLException e) {
                   e.printStackTrace();
              } finally {
                   return null;
    }

    Darkstar444 wrote:
    I deleted ListGames.class, ListGames$Games.class, and MysqlConnection.class but still the same thing.Then you didn't delete the version of ListGames.class which is actually being used when you run your application. This suggests that your classpath is pointing to an old version as well as to the version produced currently by the compiler. Or that there's an old version which you put into the Java extensions directory.

  • Exception in thread "main" java.lang.NoClassDefFoundError: Helloworld

    Hi Java Experts,
    I am at a lost to how Java searches for all the classes when running a program. Below are the following steps I have taken to try a simple basic HelloWorld.java program on the command prompt on Windows XP (SP2) platform:
    ( i ) Installed both jdk1.5.0_09 and Netbeans IDE 5.0 and working properly.
    ( ii ) The source file is located in F:\Documents and Settings\abc\HeadFirstDesignPattern\src\ch11 and the compiled file is in F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes\ch11 which was compiled in Netbeans.
    ( iii ) No problem compiling & running this program in Netbeans.
    ( iv ) The RUN CLASSPATH in Netbeans is F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes.
    ( v ) No CLASSPATH variable has been set.
    ( vi ) The HelloWorld program looks like this:
    package ch11;
    public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World!");
    ( vi ) Got the message
    "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"
    when running a combination of the following Java commands:
    ( a ) cd F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes
    ( b ) java HelloWorld, or
    java -cp . HelloWorld or java -cp "." HelloWorld, or
    java -cp F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes HelloWorld or "F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes" HelloWorld, or
    java -cp F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes;. HelloWorld or "F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes";. HelloWorld, or
    java -cp "F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes";. HelloWorld or "F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes";"." HelloWorld, or
    java -cp "F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes";. HelloWorld or "F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes";"." ch11\HelloWorld.
    It is the package location which is a subdirectory of F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes which caused Java not to find this program. I had no problem running it if the HelloWorld.java was moved one level up. ie from F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes\ch11 to F:\Documents and Settings\abc\HeadFirstDesignPattern\build\classes.
    I have written Java in the last year mostly on Netbeans without any problem running them.
    The reason for having to learn to run Java on the command line is so that I could add arguments to the program which I couldn't do in Netbeans just yet.
    I have gone through a lot of the articles from Java forums, Google searches but yet to have found a solution.
    Many thanks,
    Netbeans Fan

    I am getting the same problem when running the same program on a Fedora 4.0 (Redhat Linux 10) system, together with Netbeans 5.5 and JDK1.5.0_09. Again, I have no such problem when running the same program in Netbeans.
    Here are the steps that I have taken as follows:
    $ hostname
    spisu07.stvincents.com.au
    $ uname -a
    Linux spisu07.stvincents.com.au 2.6.11-1.1369_FC4 #1 Thu Jun 2 22:55:56 EDT 2005 i686
    $ pwd
    /home/dbi/HeadFirstDesignPattern/build/classes/ch11a
    $ cd ..
    $ pwd
    /home/dbi/HeadFirstDesignPattern/build/classes
    $ ls
    ch11a
    $ ls ch11a
    GumballMachine.class GumballMonitor.class NoQuarterState.class State.class
    GumballMachineRemote.class GumballMonitorTestDrive.class SoldOutState.class WinnerState.class
    GumballMachineTestDrive.class HasQuarterState.class SoldState.class
    $ java -cp . ch11a.GumballMachineTestDrive
    Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: ch11a.GumballMachineTestDrive
    at java.lang.VMClassLoader.transformException(java.lang.Class, java.lang.Throwable) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
    at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.6.0.0)file:///usr/share/doc/HTML/index.html
    ...4 more
    $ echo $PATH
    /usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/opt/netbeans-5.5/bin:/etc/alternatives/.:/opt/netbeans-5.5/bin:/opt/jdk1.5.0_09:/etc/alternatives/.
    $ echo $JAVA_HOME
    $ echo $CLASSPATH
    Any suggestions?
    Thanks,
    Henry

  • Exception in thread "main" java.lang.InternalError: Can't connect to X11 wi

    Hello Friends,
    I dont know whether this would be the correct forum or not but my problem is very critical so please help me.
    1. I am working on linux server where I have installed Tomcat4.x, Apache 2.0, JDK1.4.2. I have set all CLASSPATH.
    Java is working fine. I am using one JCLASS component which is useful in chart creation.
    3. Few days back the code regarding Frame cration was working fine but now its giving an error. I am actually running these files using cron and my requirement is also same.
    4. I have tried almost all possibilities like
    export DISPLAY=localhost:0.0
    export DISPLAY=ipaddress:0.0, but no luck.
    Can you explain me what could be the reason.
    JAVA ERROR:
    Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:141)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
    at sun.awt.motif.MToolkit.<clinit>(MToolkit.java:81)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:141)
    at java.awt.Toolkit$2.run(Toolkit.java:748)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:739)
    at java.awt.Toolkit.getEventQueue(Toolkit.java:1519)
    at java.awt.EventQueue.invokeLater(EventQueue.java:792)
    at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1170)
    at FrameDemo.main(FrameDemo.java:35)
    Please let me know your suggestions as possible as follows.
    PuneProgrammer

    You are probably creating images on the fly.
    Due to a bug/annoyance in the JDK, it requires an X-display. This is not related to the Sun ONE Webserver but a general problem.
    -Either install an X server, but this might not be possible because of a server security strip.
    -install a virtual X xvfb or something alike to emulate this behaviour.
    I thought it would be solved in newer JDK's but in which i'm not sure.

  • Exception in thread "main" java.lang.NoClassDefFoundError: BlueCheese

    I'm writing a simple swing application. It compiles, but I can't get it to run... I always get this error:
    Exception in thread "main" java.lang.NoClassDefFoundError: BlueCheese
    Caused by: java.lang.ClassNotFoundException: BlueCheese
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    I tried running another app, and it works just fine. Here is the source code:
    package zing.blueCheese;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BlueCheese
         private JFrame frame;
         private static void createGUI()
              JFrame frame = new JFrame("FileSmasher");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              ImageIcon icon = new ImageIcon("Mac.gif");
              JTabbedPane tabbedPane = new JTabbedPane();
              JLabel label = new JLabel("<html><font size=6>1:</font></html>");
              JPanel panel = new JPanel();
              tabbedPane.addTab("Parse", icon, panel, "Smash a file");
              panel = new JPanel();
              tabbedPane.addTab("Concatenate", icon, panel, "Assemble the smashed pieces of a file");
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args)
              SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        createGUI();
    Any suggestions?

    yawmark wrote:
    java -cp . zing.blueCheese.BlueCheeseExecuted in the directory containing the "zing" subdirectory (which itself should contain "blueCheese/BlueCheese.class"). Note the "dot" and spaces, which mean "add the current directory to the classpath". Alternately, you could add the full path to the directory containing "zing" to the classpath. Example:java -cp . path/to/dir zing.blueCheese.BlueCheese~Shouldn't that be (with appropriate path separator)
    java -cp.:path/to/dir zing.blueCheese.BlueCheese?

  • Exception in thread "main" java.lang.InternalError:

    Hi all,
    i'm installing 11.5.10.2 on RHEL 4, after running
    $cd /u01/Stage11i/startCD/Disk1/rapidwiz
    $./rapidwiz
    i get the following error
    [applmgr@eureka rapidwiz]$ Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using '192.168.10.41:1.0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(Unknown Source)
    at java.awt.Window.init(Unknown Source)
    at java.awt.Window.<init>(Unknown Source)
    at java.awt.Frame.<init>(Unknown Source)
    at java.awt.Frame.<init>(Unknown Source)
    at oracle.ewt.popup.PopupFrame.<init>(Unknown Source)
    at oracle.ewt.lwAWT.BufferedFrame.<init>(Unknown Source)
    at oracle.apps.ad.rapidwiz.RIWizard.main(RIWizard.java:2303)
    i set the DISPLAY variable logged in as the 'applmgr' the user who is going to perform the installation.
    $echo $DISPLAY gives
    192.168.10.41:1.0
    Please suggest.
    rgds,
    Krish

    Hi Alok,
    You require to do the folowing to access the console.
    1. set the DISPLAY parameter to an IP addresssuffixed with :0.0 .... Which you have done correctly.
    2. Open an Xwindow in the IP that you have just set.
    3. Fire the console shell and Xwindow will capture the output.
    In case you get any error the post it here.
    Regards,
    DJ

  • Exception in thread "main" java.lang

    hi,
    I have java app which is called cutter.jar , I wanna run it using run.bat file which contain this line:
    java -classpath .;cutter.jar Cutter
    when I run --> run.bat I get this error message:
    java -classpath cutter.jar Cutter
    Exception in thread "main" java.lang.ExceptionInInitializerError
    at Cutter.main(Cutter.java:96)
    Caused by: java.lang.NullPointerException
    at Preferences.<clinit>(Preferences.java:995)
    ... 1 more
    Please help ASAP, I'm not the Java user but must use this cutter app.
    Thanks

    Post each question only once.
    http://forum.java.sun.com/thread.jspa?threadID=5140780
    http://forum.java.sun.com/thread.jspa?threadID=5140779

Maybe you are looking for

  • Retruring Multiple rows from a Stored Procedure

    The Oracle JDBC documentation shows how to return a cursor pointer through the parameter list of a stored procedure allowing a Java program to use the cursor like a normal result set. I've tried it (using the thin driver) and it works fine - however,

  • Password Issue

    Oracle 9i Standards on Standalone with Win 2K Op. System. When created database, created/changed ID and password but system doesn't recognize. Give Ora -01017 Error. Is there a specific file to look at and fix. My SQLNET.ORA file is fine. Steve

  • InDesign Fonts problem Bookmark Script

    Dear All, We developed one script for creation of Bookmark in InDesign CS2. When we are runnign this script content formatting is getting anmoly changed, I analyzed InDesign file and came to know that due to a font called "Trade Gothic Bold No. 2" du

  • FPGA event Structure

    Hi, Iam working on DC motor...... iam using NI 9505....... iam using example code of labview {(Position Control (closed loop)- under compact RIO}...... every thing is fine............ now i want to add control LEDs which has to control the speed of t

  • JDBC CONNECTIONS RECURSIVE WAY

    JAVA DEVELOPER COMUNITY I request your help in the following topic, i am doing a java program that store a complete file system in an Oracle Database 11GR2. So i use a recursive algorithm to do that but i don't know how to handle the JDBC connections