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");

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

  • 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 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:....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~>

  • Exception in thread "main" java.lang.UnsupportedClassversion error.

    hi,
    I am having the JDk and jre versions in C: drive
    i am jdk version 1.5.0
    but when i am running the command version it is showing 1.4.2_03 version and also i am having the oracle 10g on my system.
    tried seeting classpath also but no success.
    I am trying to run a simple helloworld program.while compiling there seems to be no problem..
    But while running the program i am encountring the following error.
    Exception in thread "main" java.lang.UnsupportedClassversion error.
    can someone help me regarding this

    Classpath is NOT going to help. You may be able to fix this by putting the JDK bin directory as the first entry in your system's PATH variable.

  • "Exception in thread "main" java.lang.NoClassDefFound Error" in XP

    I was creating programs just fine for awhile. Then, for some unknown reason, I start getting the runtime error message, "Exception in thread "main" java.lang.NoClassDefFound Error." I set my PATH in the following manner:
    Start | Control Panel | Performance and Maintenance | System | Advanced | Environment Variables | Use Variables for Owner | PATH | Edit | C:\j2sdk1.4.2_04;C:\j2sdk1.4.2_04\bin;C:\j2sdk1.4.2_04\jre\bin | Ok | Ok | Ok
    I then closed the dialog boxes and restarted my computer. I then tried to run a program that ran before, only to get the same runtime error! Can someone please help me???

    NoClassDefFoundError happens because the JVM cannot find some class from your program, not because the OS cannot find your JVM (PATH regulates the latter, but not the former). JVM looks up classes in directories (or JAR files) specified through the -classpath option, like "java -classpath c:\myclasses MyMainClass". Read the online doc for the "java" launcher for more info.

  • Error:"exception in thread main:java.lang.noclassdeffound error.

    Hi,
    I am new to this java tech and programming. I just started learning and installed j2sdk1.4.0_03. I wrote a small hello world program and compiled it without any errors. When I execute the same using java hello command, I am getting an error like this: exception in thread "main" java.lang.noclassdeffound error. I am not able to resolve this issue. Please let me know the sol.
    thanks
    venkatraman

    send the program u have typedUmm... Why?
    Anyway @NovaKane: Welcome. Together with seifist and sunny we have at
    least three new posters who show enough intelligence to find chuck's
    solution (or one of the many hundreds of others like it) and the politeness
    to thank him for it. What's the forum coming to?
    If you need it there is a description of the classpath here:
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html
    Again, welcome. And thanks for raising the intelligence level (and politeness
    quotient) of the fora.

  • Exception in thread "main" java.lang.UnsatisfiedLinkError ERROR

    Hi All,
    I am trying to develop a Swing Application. I have compiled my codes in Windows like this:
    javac -d ../../classes *.javaThen I tried to run the program from <my dir>/classes/ folder...
    java com.fusion.ucmrtnd.Mainwhere Main.java contains the main() method.
    But I am getting the following error:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: sun.awt.SunToolkit.getAppContext(Ljava/lang/Object;)Lsun/awt/AppContext;
            at sun.awt.SunToolkit.getAppContext(Native Method)
            at sun.awt.SunToolkit.targetToAppContext(Unknown Source)
            at sun.awt.windows.WComponentPeer.postEvent(Unknown Source)
            at sun.awt.windows.WComponentPeer.replaceSurfaceDataLater(Unknown Source)
            at sun.awt.windows.WWindowPeer.updateInsets(Native Method)
            at sun.awt.windows.WWindowPeer.initialize(Unknown Source)
            at sun.awt.windows.WFramePeer.initialize(Unknown Source)
            at sun.awt.windows.WComponentPeer.<init>(Unknown Source)
            at sun.awt.windows.WCanvasPeer.<init>(Unknown Source)
            at sun.awt.windows.WPanelPeer.<init>(Unknown Source)
            at sun.awt.windows.WWindowPeer.<init>(Unknown Source)
            at sun.awt.windows.WFramePeer.<init>(Unknown Source)
            at sun.awt.windows.WToolkit.createFrame(Unknown Source)
            at java.awt.Frame.addNotify(Unknown Source)
            at javax.swing.SwingUtilities$SharedOwnerFrame.addNotify(Unknown Source)
            at java.awt.Dialog.addNotify(Unknown Source)
            at java.awt.Dialog.conditionalShow(Unknown Source)
            at java.awt.Dialog.show(Unknown Source)
            at java.awt.Component.show(Unknown Source)
            at java.awt.Component.setVisible(Unknown Source)
            at java.awt.Window.setVisible(Unknown Source)
            at java.awt.Dialog.setVisible(Unknown Source)
            at DisplayStrip.DisplayStripRun(DisplayStrip.java:32)
            at Main.main(Main.java:8)PS: I used NetBeans 6.5 IDE, where it's working fine. But when I am trying to deploy the codes in Windows, I am getting this error.
    Any help would be appreciated.
    TiA....

    maybe your rt.jar conflicting

  • Exception in thread "main" java.lang.ClassFormat Error

    I am running a java program in NeBeans and when I run the program I am getting the following error:
    Exception in thread "main" java.lang.ClassFormatError: Repetitive method name/signature in class file pluginex2/TtsoapcgiPortType_addLink_ResponseStruct_SOAPSerializer
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at pluginex2.Ttsoapcgi_SerializerRegistry.getRegistry(Ttsoapcgi_SerializerRegistry.java:73)
    at pluginex2.Ttsoapcgi_Impl.<init>(Ttsoapcgi_Impl.java:25)
    at pluginex2.Main.main(Main.java:25)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    What should I do?Can anyone please help me out?
    Thanks,
    Sravanthi.

    The class files are automatically into the build/generated/wsclient/project-name file of my project.
    I copied those class files into my source folder to make my program work.When I searched my system I jus found two of these files in build/generated/wsclient/project-name folder and source folder of my project.
    I am running the program directly through NetBeans IDE.

  • "Exception in thread "main" java.lang.NumberFormatException"error..pls help

    Hi,
    I'm trying to run a program I've written but keeping getting this error:
    Exception in thread "main" java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
    at java.lang.Double.parseDouble(Double.java:482)
    at data.newLineToRead(data.java:21)
    at data.data(data.java:34)
    at train.main(train.java:86)
    I'm not quite sure where I'm going wrong.I've included the data class and train class.Could someone pls help me.
    Thanks a lot.
    Data Class:
    import java.io.*;
    import java.util.*;
    public class data{
            private static parameter par;
            private static double[][] x=new double[par.n()][par.D()];
            public static double[] t=new double[par.n()];
            public static void newLineToRead(String LineToRead,int n){
            int d=0;
            String stringToRead=new String();
                    for(int i=0;i<=LineToRead.length();i++){
                            StringTokenizer str = new StringTokenizer (stringToRead,"/t");
                            String[] strtemp = new String[str.countTokens()];
                                    while (str.hasMoreTokens()){
                                    x[n][d++] = Double.parseDouble(str.nextToken());
                                    d++;
                                    System.out.println(x[n][d++]);
                            stringToRead=new String();
                    t[n]=Double.parseDouble(stringToRead);
                    x[n][par.d()]=1.0;
            public static void data() throws IOException{
            DataInputStream in=null;
                    try{
                            in=new DataInputStream(new FileInputStream(par.f()));
                            for(int n=0;n<par.n();n++){
                            String LineToRead=in.readLine();
                                    if(LineToRead.length()==0){
                                            System.out.println("Remove empty lines");
                                    else{
                                            newLineToRead(LineToRead,n);
                    }finally{if(in!=null){in.close();}}
            public static double x(int n,int d){return x[n][d];}
            public static double t(int n){return t[n];}
    }Train Class
    import java.io.*;
    import java.util.*;
    public class train{
             private static parameter       par;
             private static data            dat;
             private static model           mod;
             private static response        resp;
             private static void error(String msg){
                    System.out.println(msg);
                    System.exit(1);
             private static void check(){
                if(par.f().length()==0)
                    error("No filename of input vectors!");
                if(par.n()==0)
                    error("No number of input vectors!");
                if(par.d()==0)
                    error("No number of input variables!");
                if(par.d()>par.D())
                    error("Dimension is larger than 100!");
              private static void usage(){
                System.out.println("Non-default parameters==========================");
                System.out.println("-f filename of input vectors");
                System.out.println("-n number of input vectors");
                System.out.println("-d number of input variables");
                System.out.println("Default parameters==========================");
                System.out.println("-R regularisation constant (must be positive and the default value is 0.0)");
                System.out.println("-S epsilon criterion for stopping a learning process (default value is 0.001)");
                System.out.println("-C maximum learning cycle (default value is 10000)");
                      public static void main(String[] argv){
                            if(argv.length==0){
                                    System.out.println("Command line is <Java [-cp path] train parameters>");
                                    usage();
                                    System.exit(1);
                            if(argv.length==1 && argv[0].equals("help")==true){
                                    usage();
                                    System.exit(1);
                            par.nin(0); par.din(0); par.Rin(0.0); par.Cin(10000); par.Sin(0.001);
    for(int i=0;i<argv.length;i++){
                                            if(argv.equals("-f")==true){
    if((i+1)==argv.length)
    error("miss the para");
    par.fin(argv[i+1]);
    i++;
    else if(argv[i].equals("-d")==true){
    if((i+1)==argv.length)
    error("miss the para");
    par.din(Integer.parseInt(argv[i+1]));
    i++;
    else if(argv[i].equals("-n")==true){
    if((i+1)==argv.length)
    error("miss the para");
    par.nin(Integer.parseInt(argv[i+1]));
    i++;
    else if(argv[i].equals("-S")==true){
    if((i+1)==argv.length)
    error("miss the para");
    par.Sin(Integer.parseInt(argv[i+1]));
    i++;
    else if(argv[i].equals("-C")==true){
    if((i+1)==argv.length)
    error("miss the para");
    par.Cin(Integer.parseInt(argv[i+1]));
    i++;
    else if(argv[i].equals("-R")==true){
    if((i+1)==argv.length)
    error("miss the para");
    par.Rin(Double.parseDouble(argv[i+1]));
    i++;
    else error("Unkown token");
    check();
    try {
    dat.data();
    }catch(IOException e) { System.err.println(e.toString()); }
    try {
    mod.model();
    }catch(IOException e) { System.err.println(e.toString()); }
    try {
    resp.record();
    }catch(IOException e){ System.err.println(e.toString()); }

    String stringToRead=new String();
                    for(int i=0;i<=LineToRead.length();i++){
                            StringTokenizer str = new StringTokenizer (stringToRead,"/t");
                            String[] strtemp = new String[str.countTokens()];
                                    while (str.hasMoreTokens()){
                                    x[n][d++] = Double.parseDouble(str.nextToken());
                                    d++;
                                    System.out.println(x[n][d++]);
                            stringToRead=new String();
                    t[n]=Double.parseDouble(stringToRead);
                    x[n][par.d()]=1.0;
            }Not sure exactly what you are trying to do above but...
    You are setting your String to an empty String with "new String()" and then parsing that empty String. Eventually, you are trying to parse a double from that empty String:
    t[n]=Double.parseDouble(stringToRead);Also, I cannot think of a reason to ever use "new String()" when you could just use:
    String myString = "";

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to solve this problem"exception in thread "main" java.lang.noclassdeff"

    I am a tyro of java programming .
    i downloaded the j2sdk-1_4_2_09-windows-i586-p.exe from www.java.sun.com and installed it at the defaulted path C:\j2sdk1.4.2_09,
    then i wrote down my first java program as follow:
    public class hello
    public static void main (String args[])
    System.out.println("hello,����!");
    }and stored it at C:\Javasmp\ch01\hello.java.
    after that i opened dos commind window and compiled it :
    c:\javac C:\Javasmp\ch01\hello.java. and obtained file hello.class (C:\Javasmp\ch01\hello.class)
    but when running it (c:\java C:\Javasmp\ch01\hello) there was a mistake:
    exception in thread "main"java.lang.noclassdeffounderror:C:\Javasmp\ch01\hello
    i searched on the internet and found out the solution is set enviroment viriable ,so i set the "CLASSPATH" as".;C:\j2sdk1.4.2_09\lib;C:\j2sdk1.4.2_09\lib\tools.jar" ,"PATH" as"C:\j2sdk1.4.2_09\bin;C:\Windows\system32;c:\windows\system32\Wbem" and "JAVA_HOME" as "C:\j2sdk1.4.2_09\bin;C:\j2sdk1.4.2_09\jre\bin"
    afer that, i opened a new dos command window and run it again ,but the problem was still unsolved.
    in addition,my os is "windows xp"
    anyone can help me ,thank you!
    i am a student in China,it's a hard time for me to write down my question in english ,i doubt whether i express my question clearly.
    thank you for you reading.

    I have created a simple applet.
    import java.lang.*;
    import java.awt.*;
    public class jawtex3 extends java.applet.Applet
    public void init()
    add(new Button("One"));
    add(new Button("Two"));
    public Dimension preferredSize()
    return new Dimension(200, 100);
    public static void main(String [] args)
    Frame f = new Frame(" jawtex3");
    jawtex3 ex = new jawtex3();
    ex.init();
    f.add("Center", ex);
    f.pack();
    f.show();
    In this no compilation errors.
    I am getting runtime exception.as Exception in thread "main"java.lang.NoClassDefFound Error: jawtex
    reply me soon.
    thankyou.

Maybe you are looking for

  • What's new in 7.1.0.714 (Bundle 2039)

    what is new in new 7.1.0.714 (Bundle 2039) for 9360 curve  Thanks for help  

  • Device error 370 please tech support help

    How do you fix this There is a reset link with it but all it does is come back to to the same message no rebooting at all please tech support help 

  • Credit management for IT industry

    Hi, As we want to use credit management functionality of SAP but really not understand how to implement it Means at level check should be happen because we are a service industry where we have contract with customer for varying periods 1 year,2 year.

  • Customize Lync Meeting Invitation

    I was looking for a way to change the default meeting invite email but I guess there isn't any way to do this. You can customize the invitation using Exchange Server's transport rules. Can someone help how to do that and how it will work ? Currently

  • TFS 2010: Query over all Collections and Team Projects

    Hi, is it possible to generate a query which queries all collections and team project on a TFS? For example if I want to know all work items assigned to me. Actually I can only query over a collection and not over the complete TFS. How can I do this?