6 Replies Latest reply: Apr 17, 2013 5:50 AM by EJP RSS

    Getting an Exception Unable to create Object

    896976
      I have the following methos I am getting the unable to create the file exception
      I believe the problem is when is trying to read the object I try the following
       record.setMessage(input.readObject().toString()); 
                ///  record = (Message)input.readObject();
      1) convert the object to a string
      record.setMessage(input.readObject().toString()); 
      2) I also try this
       record = (Message)input.readObject()
      Notice that I put the put the file into the cryptpText area and then I get into a String
      cipherTextString = record.toString(); 
               
               //put string in JTextArea 
               
                cipherTextArea.setLineWrap(true); 
                cipherTextArea.setText(cipherTextString); 
      Here is the setMessage Method in the Message class
      set
       public void setMessage(String eMessage)
       {    
           myMessage = eMessage;
       }
       
      public void performStartTask() 
          {
              //choose the file to open 
              int returnVal; 
              String inputFileName = ""; 
                    
              
              //open a JFileChoose 
              
              JFileChooser chooser = new JFileChooser(new File (
                      "C:\\Java_code\\java_files")); 
              
              chooser.setDialogTitle("Please select an encoded file"); 
              
              returnVal = chooser.showOpenDialog(null); 
              
              if(returnVal == JFileChooser.APPROVE_OPTION)
              {
                  inputFileName = chooser.getSelectedFile().getName();
              }
               
              //Open the file 
              
              ObjectInputStream input  = null; 
              
              //exception handlig here
              try 
              {
                  input = new ObjectInputStream( new FileInputStream("C:\\Java_code\\java_files\\" + inputFileName));
              }
             
                catch (IOException e)
                    
                {
                    System.err.println("error opening the file"); 
                } 
                  
                //read from the file 
              record = null; 
              record = new Message();
              try 
              {
                 record.setMessage(input.readObject().toString()); 
                ///  record = (Message)input.readObject();
               
              }
               catch(EOFException eofe)           
               {
                   return; 
               }
               catch(ClassNotFoundException cnfe) 
               {
                        System.err.println("Unable to create Object"); 
               }
               catch(IOException ioe) 
               {
                   System.err.println("Error reading from file "); 
               } // end try catch 
             
                  
             System.out.println("Just read in" + record + "." + record.getShift()); 
             
               //put the file into the cryptpText area
               //first - get into a string 
               
               cipherTextString = record.toString(); 
               
               //put string in JTextArea 
               
                cipherTextArea.setLineWrap(true); 
                cipherTextArea.setText(cipherTextString); 
                
               closeFile(input);
                
                startBoolean = true; 
                
          } // End of performedStartMethod  
        • 1. Re: Getting an Exception Unable to create Object
          Kayaman
          Use e.printStackTrace() to show the whole exception. Otherwise you won't get any useful information from your errors.
          • 2. Re: Getting an Exception Unable to create Object
            896976
            Sorry I am new at this where exactly I will put that code
            Thank you
            • 3. Re: Getting an Exception Unable to create Object
              896976
              Ok I added this piece of code, hope is right
               catch (Exception e) {
                        StackTraceElement[] stack = e.getStackTrace();
                          String exception = "";
                         for (StackTraceElement s : stack) {
                      exception = exception + s.toString() + "\n\t\t";
                  }
                  System.out.println(exception);
              anf it shows that the error is here

              record.setMessage(input.readObject().toString());



              java.net.URLClassLoader$1.run(URLClassLoader.java:366)
                        java.net.URLClassLoader$1.run(URLClassLoader.java:355)
                        java.security.AccessController.doPrivileged(Native Method)
                        java.net.URLClassLoader.findClass(URLClassLoader.java:354)
                        java.lang.ClassLoader.loadClass(ClassLoader.java:423)
                        sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
                        java.lang.ClassLoader.loadClass(ClassLoader.java:356)
                        java.lang.Class.forName0(Native Method)
                        java.lang.Class.forName(Class.java:264)
                        java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:622)
                        java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593)
                        java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
                        java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
                        java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
                        java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
                        lab01recheverri.Lab01recheverri.performStartTask(Lab01recheverri.java:172)
                        lab01recheverri.Lab01recheverri.actionPerformed(Lab01recheverri.java:103)
                        javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
                        javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
                        javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
                        javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
                        javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
                        java.awt.Component.processMouseEvent(Component.java:6505)
                        javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
                        java.awt.Component.processEvent(Component.java:6270)
                        java.awt.Container.processEvent(Container.java:2229)
                        java.awt.Component.dispatchEventImpl(Component.java:4861)
                        java.awt.Container.dispatchEventImpl(Container.java:2287)
                        java.awt.Component.dispatchEvent(Component.java:4687)
                        java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
                        java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
                        java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
                        java.awt.Container.dispatchEventImpl(Container.java:2273)
                        java.awt.Window.dispatchEventImpl(Window.java:2719)
                        java.awt.Component.dispatchEvent(Component.java:4687)
                        java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
                        java.awt.EventQueue.access$000(EventQueue.java:102)
                        java.awt.EventQueue$3.run(EventQueue.java:662)
                        java.awt.EventQueue$3.run(EventQueue.java:660)
                        java.security.AccessController.doPrivileged(Native Method)
                        java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
                        java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
                        java.awt.EventQueue$4.run(EventQueue.java:676)
                        java.awt.EventQueue$4.run(EventQueue.java:674)
                        java.security.AccessController.doPrivileged(Native Method)
                        java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
                        java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
                        java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
                        java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
                        java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
                        java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
                        java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
                        java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
                        
              Just read innull.0
              • 4. Re: Getting an Exception Unable to create Object
                thomas.behr
                In your catch-blocks! Instead of System.err.println do e.printStackTrace() (e being the caught exception.
                • 5. Re: Getting an Exception Unable to create Object
                  896976
                  did it got the same results

                  Again the problem is here
                  record.setMessage(input.readObject().toString());

                  java.lang.ClassNotFoundException: Message
                  Just read innull.0
                       at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
                       at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
                       at java.security.AccessController.doPrivileged(Native Method)
                       at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
                       at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
                       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
                       at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
                       at java.lang.Class.forName0(Native Method)
                       at java.lang.Class.forName(Class.java:264)
                       at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:622)
                       at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593)
                       at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
                       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
                       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
                       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
                       at lab01recheverri.Lab01recheverri.performStartTask(Lab01recheverri.java:172)
                       at lab01recheverri.Lab01recheverri.actionPerformed(Lab01recheverri.java:103)
                       at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
                       at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
                       at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
                       at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
                       at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
                       at java.awt.Component.processMouseEvent(Component.java:6505)
                       at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
                       at java.awt.Component.processEvent(Component.java:6270)
                       at java.awt.Container.processEvent(Container.java:2229)
                       at java.awt.Component.dispatchEventImpl(Component.java:4861)
                       at java.awt.Container.dispatchEventImpl(Container.java:2287)
                       at java.awt.Component.dispatchEvent(Component.java:4687)
                       at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
                       at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
                       at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
                       at java.awt.Container.dispatchEventImpl(Container.java:2273)
                       at java.awt.Window.dispatchEventImpl(Window.java:2719)
                       at java.awt.Component.dispatchEvent(Component.java:4687)
                       at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
                       at java.awt.EventQueue.access$000(EventQueue.java:102)
                       at java.awt.EventQueue$3.run(EventQueue.java:662)
                       at java.awt.EventQueue$3.run(EventQueue.java:660)
                       at java.security.AccessController.doPrivileged(Native Method)
                       at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
                       at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
                       at java.awt.EventQueue$4.run(EventQueue.java:676)
                       at java.awt.EventQueue$4.run(EventQueue.java:674)
                       at java.security.AccessController.doPrivileged(Native Method)
                       at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
                       at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
                       at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
                       at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
                       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
                       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
                       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
                       at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
                  • 6. Re: Getting an Exception Unable to create Object
                    EJP
                    Come off it. Try e.printStackTrace(). You don't need all that crud. You haven't even printed the exception itself this way.