Results 1 to 14 of 14
  1. #1
    bach_meoden is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Cool Error after build to jar file.

    I have a project working with COM port using comm.jar. It run correctly when i try run on Netbean, but when i build it to jar file, after that run jar file and error occured:
    Thanks !
    ---------------------

    C:\Documents and Settings\Administrator>java -jar d:\controls\writecomm\dist\wri
    tecomm.jar
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at SourceCode.COM.writeData(COM.java:76)
    at SourceCode.Manipulations.SendToDevices(Manipulatio ns.java:57)
    at SourceCode.Main.BrowseActionPerformed(Main.java:14 8)
    at SourceCode.Main.access$000(Main.java:27)
    at SourceCode.Main$2.actionPerformed(Main.java:90)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Sour
    ce)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    C:\Documents and Settings\Administrator>

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    What the package you use? Complete dist folder or not?

    Did you get any error message when you build the project in NetBeans?

  3. #3
    bach_meoden is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default thanks

    when i run in netbean, no error occured. i build and run file .jar in dist folder and program has error.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I'm asking that did you get any errors when you build the project. If there is no any errors at the build, you can see a command in output window that the process is success. It'll show you that the command you want to use in execution. Is that ok?

  5. #5
    bach_meoden is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default error

    init:
    deps-clean:
    Updating property file: D:\Controls\WriteComm\build\built-clean.properties
    Deleting directory D:\Controls\WriteComm\build
    clean:
    init:
    deps-jar:
    Created dir: D:\Controls\WriteComm\build
    Updating property file: D:\Controls\WriteComm\build\built-jar.properties
    Created dir: D:\Controls\WriteComm\build\classes
    Created dir: D:\Controls\WriteComm\build\empty
    Compiling 5 source files to D:\Controls\WriteComm\build\classes
    Copying 2 files to D:\Controls\WriteComm\build\classes
    compile:
    Created dir: D:\Controls\WriteComm\dist
    Building jar: D:\Controls\WriteComm\dist\WriteComm.jar
    Copy libraries to D:\Controls\WriteComm\dist\lib.
    To run this application from the command line without Ant, try:
    java -jar "D:\Controls\WriteComm\dist\WriteComm.jar"
    jar:
    BUILD SUCCESSFUL (total time: 2 seconds)
    ----------------------
    in command dos i type :java -jar "D:\Controls\WriteComm\dist\WriteComm.jar"
    jar: to run program but it not run correct

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by bach_meoden View Post
    in command dos i type :java -jar "D:\Controls\WriteComm\dist\WriteComm.jar"
    jar: to run program but it not run correct
    So your application doesn't have any build errors.

    Okay, now you said that you can run the application from the NetBeans without an error. But now look at the error message, NullPointerException at SourceCode.COM.writeData(COM.java:76)

    I think this is not your class, COM.java. But somehow you pass a null value to it. Could you figure it out?

  7. #7
    bach_meoden is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    COM is my class, i write it to work with COM port.
    Nullpointer exception throw when try to run command: outputStream.write(bytedata); to write data to com.
    ---------here is code of COM
    byte[] bytedata=s.getBytes("US-ASCII");
    if(bytedata!=null)
    try{
    outputStream.write(bytedata);
    }catch(NullPointerException e)
    {
    JOptionPane.showMessageDialog(null, e.getMessage());
    e.printStackTrace();
    System.exit(0);
    }
    else
    JOptionPane.showMessageDialog(null,"Data null");

  8. #8
    bach_meoden is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    But when i run on IDE NetBean, there is no exceptions throw and it run ok, data write to com port correctly.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    That's not the complete code of your class. Check on line 76 what's happening.

    COM.writeData(COM.java:76)

  10. #10
    bach_meoden is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default Complete Code of COM class

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package SourceCode;
    
    /**
     *
     * @author Administrator
     */
    import java.io.*;
    import java.util.*;
    import javax.comm.CommPortIdentifier;
    import javax.comm.PortInUseException;
    import javax.comm.SerialPort;
    import javax.comm.UnsupportedCommOperationException;
    import javax.swing.JOptionPane;
    
    public class COM {
       private CommPortIdentifier portId;
       private Enumeration        portList;
       private SerialPort           serialPort;
       private OutputStream      outputStream;
    
        public COM() {
                    try{
                         //Initial Port COM1
                    String defaultPort = "COM1";
                    portList = CommPortIdentifier.getPortIdentifiers();
                    while (portList.hasMoreElements()) {
                        portId = (CommPortIdentifier) portList.nextElement();
                        if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                            if (portId.getName().equals(defaultPort)) {
                        serialPort = (SerialPort)portId.open("devices", 2000);
                        // Set port parameters
                        outputStream = serialPort.getOutputStream();
                        serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
                        serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                       /*
                        Thuc hien tao doi tuong va ghi ra cong COM.
                        */
                            }
                        }
               }
        }
            catch(IOException e)
            {
            JOptionPane.showMessageDialog(null, "Error Open IO Stream, repare and retry!","VIEGRIDJSC",JOptionPane.ERROR_MESSAGE);
            System.exit(0);
            }
            catch(PortInUseException e)
            {
            JOptionPane.showMessageDialog(null,"Check Port COM in use, repare and retry!","VIEGRIDJSC",JOptionPane.ERROR_MESSAGE);
            System.exit(0);
            }
            catch(UnsupportedCommOperationException e)
            {
            JOptionPane.showMessageDialog(null,"Not found Comm.jar in java\\JDK1.1.8\\LIB\\, repare and retry!","VIEGRIDJSC",JOptionPane.ERROR_MESSAGE);
            System.exit(0);
            }
        }
        public void CloseCom()
        {
        serialPort.close();
        try{
        outputStream.close();
        }catch(IOException e)
        {
        JOptionPane.showMessageDialog(null,"Can't close COM output","VIEGRIDJSC",JOptionPane.ERROR_MESSAGE);
        }
        }
    public void writeData(String s)
        {
        try{
            byte[] bytedata=s.getBytes("US-ASCII");
            if(bytedata!=null)
                try{
                 outputStream.write(bytedata);
                }catch(NullPointerException e)
                {
                JOptionPane.showMessageDialog(null, e.getMessage());
                e.printStackTrace();
                System.exit(0);
                }
            else
                JOptionPane.showMessageDialog(null,"Data null");
        }
        catch(IOException e)
        {
            JOptionPane.showMessageDialog(null,"Can't write to COM","VIEGRIDJSC",JOptionPane.ERROR_MESSAGE);
        }
        }
    }
    Last edited by Eranga; 04-05-2010 at 04:00 AM. Reason: code tags added

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Check on line 76 lol, I couldn't find it easily in the above code. And also please use code tags next time.

  12. #12
    bach_meoden is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    This error because can't found port COM, but i can't found reasons!
    when i run on netbean, i can write data to COM exactly.:confused::mad:

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    As I point out at runtime some value is set to null. Can you post what exactly in line 76 in your code?

  14. #14
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    802
    Rep Power
    6

    Default

    Hi,
    One small suggestion here.
    Inside COM()
    if portlist is there then only OutPutStream is instantiated....Might be it is null...Just put SOP inside this while() and check...
    Ramya:cool:

Similar Threads

  1. can someone help me compile and build a jar file
    By peahead in forum New To Java
    Replies: 2
    Last Post: 02-06-2010, 04:05 PM
  2. How to build a .car file in Vignette?
    By andrew222 in forum Advanced Java
    Replies: 4
    Last Post: 11-23-2009, 04:08 AM
  3. Error when build by j2me wireless toolkit
    By matvey in forum Sun Java Wireless Toolkit
    Replies: 3
    Last Post: 10-23-2009, 06:34 PM
  4. how i can build exe file??
    By ahmed13 in forum Advanced Java
    Replies: 10
    Last Post: 02-06-2009, 07:54 AM
  5. How to run/build the JSP file using Eclipse
    By cbklp in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-19-2008, 12:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •