Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: HELP,java problem *java.lang.NullPointerException*

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Location
    West Java,Indonesia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question What's happen with this???

    error.jpg

    what's the mean of "Exception in thread "main" java.lang.NullPointerException"

    and when i was tryin Clean and Build my project the another message was appear

    *To run this application from the command line without Ant,try:
    java -jar "D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMo tor\dist\AplikasiPenjualanMotor.jar*

    help me fix this one please


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What's happen with this???

    java.lang.NullPointerException
    The first place to look for a description of an exception is in the API doc.
    Look at the doc for the NullPointerException class where several reasons are given for why this error happened.

    The full text of the error message gives the line number where the error happened. Here I'll use ??? because you did not post the full text of the error message with the line number.

    There is a variable with a null value on line ???. Look at line ??? in the your source and see what variable is null. Then backtrack in the code to see why that variable does not have a valid value.
    If you can not tell which variable it is, add a println just before line ??? and print out the values of all the variables on that line.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Location
    West Java,Indonesia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's happen with this???

    soo sorry bout that,i'm new member here
    this the code

    package Agung;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    public class Main {
     
        public static void main(String[] args) {
            // TODO code application logic here
           LaunchProgressBar lp = new LaunchProgressBar();
            lp.setVisible(true);
            for(int i=0;i<=100;i++){
                try {
                    lp.getProgressBar().setValue(i);
                    Thread.sleep(30);
                }catch (InterruptedException ex){
                    Logger.getLogger(LaunchProgressBar.class.getName()).log(Level.SEVERE,null,ex);
                }
            }
     
            lp.dispose();
            Login jFL = new Login();
            jFL.setVisible(true);
        }
    }

    and i got
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
    at Agung.BgSplash.<init>(LaunchProgressBar.java:123)
    at Agung.LaunchProgressBar.<init>(LaunchProgressBar.j ava:15)
    at Agung.Main.main(Main.java:9)
    BUILD STOPPED (total time: 3 seconds)
    Last edited by Norm; February 24th, 2014 at 11:20 AM. Reason: Moved highlight tag

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Location
    West Java,Indonesia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question HELP,java problem *java.lang.NullPointerException*

    error.jpg

    this the code from main.java
    package Agung;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    public class Main {
     
        public static void main(String[] args) {
            // TODO code application logic here
           LaunchProgressBar lp = new LaunchProgressBar();
            lp.setVisible(true);
            for(int i=0;i<=100;i++){
                try {
                    lp.getProgressBar().setValue(i);
                    Thread.sleep(30);
                }catch (InterruptedException ex){
                    Logger.getLogger(LaunchProgressBar.class.getName()).log(Level.SEVERE,null,ex);
                }
            }
     
            lp.dispose();
            Login jFL = new Login();
            jFL.setVisible(true);
        }
     
     
    }

    this from LaunchProgressBar.java
    package Agung;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Toolkit;
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JProgressBar;
    import javax.swing.plaf.PanelUI;
     
    public class LaunchProgressBar extends javax.swing.JDialog {
        public LaunchProgressBar() {
            setUndecorated(true);
            initComponents();
            this.setAlwaysOnTop(true);
            SplashPanel.setUI(new BgSplash());
            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
            int x = (dim.width-getWidth())/2;
            int y = (dim.height-getHeight())/2;
            setLocation(x,y);
            ProgressBar.setStringPainted(true);
        }
    public JProgressBar getProgressBar() {
        return ProgressBar;
    }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            SplashPanel = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            ProgressBar = new javax.swing.JProgressBar();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
     
            SplashPanel.setBackground(new java.awt.Color(153, 153, 153));
     
            jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
            jLabel1.setText("Aplikasi Penjualan Motor");
     
            jLabel2.setText("V.1.0.0");
     
            jLabel3.setText("Loading...");
     
            jLabel4.setText("Design by : Agung R");
     
            javax.swing.GroupLayout SplashPanelLayout = new javax.swing.GroupLayout(SplashPanel);
            SplashPanel.setLayout(SplashPanelLayout);
            SplashPanelLayout.setHorizontalGroup(
                SplashPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(ProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
                .addGroup(SplashPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel3)
                    .addContainerGap(336, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SplashPanelLayout.createSequentialGroup()
                    .addContainerGap(229, Short.MAX_VALUE)
                    .addComponent(jLabel4)
                    .addGap(68, 68, 68))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SplashPanelLayout.createSequentialGroup()
                    .addContainerGap(102, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGap(100, 100, 100))
                .addGroup(SplashPanelLayout.createSequentialGroup()
                    .addGap(179, 179, 179)
                    .addComponent(jLabel2)
                    .addContainerGap(180, Short.MAX_VALUE))
            );
            SplashPanelLayout.setVerticalGroup(
                SplashPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(SplashPanelLayout.createSequentialGroup()
                    .addGap(37, 37, 37)
                    .addComponent(jLabel1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel2)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 140, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel4)
                    .addGap(12, 12, 12))
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(SplashPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(SplashPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
     
            pack();
        }// </editor-fold>                        
     
        /**
        * @param args the command line arguments
        */
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JProgressBar ProgressBar;
        private javax.swing.JPanel SplashPanel;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        // End of variables declaration                   
    }
     
    class BgSplash extends PanelUI {
    ImageIcon background = new ImageIcon(getClass().getResource("/Agung/images/loading.gif"));
    @Override
    public void paint(Graphics g, JComponent c) {
            g.drawImage(background.getImage(), 0, 0, null);
        }
    }

    when i run this,i got :
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
    at Agung.BgSplash.<init>(LaunchProgressBar.java:123)
    at Agung.LaunchProgressBar.<init>(LaunchProgressBar.j ava:15)
    at Agung.Main.main(Main.java:9)
    BUILD STOPPED (total time: 3 seconds)

    when i clean and build this project,i got this :
    init:
    deps-clean:
    Updating property file: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build\built-clean.properties
    Deleting directory D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build
    clean:
    init:
    deps-jar:
    Created dir: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build
    Updating property file: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build\built-jar.properties
    Created dir: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build\classes
    Created dir: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build\empty
    Compiling 5 source files to D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build\classes
    Note: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\src\Agung\Login.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Copying 8 files to D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\build\classes
    compile:
    Created dir: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\dist
    Building jar: D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\dist\AplikasiPenjualanMotor.jar
    Copy libraries to D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMot or\dist\lib.
    To run this application from the command line without Ant, try:
    java -jar "D:\Encoding\AppPenjualanMotor\AplikasiPenjualanMo tor\dist\AplikasiPenjualanMotor.jar"
    jar:
    BUILD SUCCESSFUL (total time: 5 seconds)

    help me please

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What's happen with this???

    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
    at Agung.BgSplash.<init>(LaunchProgressBar.java:123)
    There is a variable with a null value on line 123. Look at line 123 in the your source and see what variable is null. Then backtrack in the code to see why that variable does not have a valid value.
    If you can not tell which variable it is, add a println just before line 123 and print out the values of all the variables on that line.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java.lang.NullPointerException
    By tangara in forum Exceptions
    Replies: 14
    Last Post: August 12th, 2013, 06:34 AM
  2. Exception in thread "main" java.lang.NullPointerException problem.......
    By Adam802 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2012, 02:23 AM
  3. Problem with java.lang.NullPointerException
    By more_dread in forum Exceptions
    Replies: 11
    Last Post: November 21st, 2011, 06:42 AM
  4. [SOLVED] Java run time error: 'java.lang.NullPointerException"
    By ChandanSharma in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 20th, 2011, 11:53 AM
  5. problem in java.lang.NullPointerException
    By jianghuzai in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 28th, 2010, 10:24 AM