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 4 of 4

Thread: Can somone please check my code???

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can somone please check my code???

    keep getting ERROR in eclipse

    Exception in thread "main" java.lang.NullPointerException
    at com.jbooktrader.platform.util.MessageDialog.showEx ception(MessageDialog.java:23)
    at com.jbooktrader.platform.startup.JBookTrader.main( JBookTrader.java:62)





    First page for this first message
    ---------------------------------------------------
    package com.jbooktrader.platform.util;
     
    import com.jbooktrader.platform.model.*;
    import com.jbooktrader.platform.startup.*;
     
    import javax.swing.*;
     
    /**
     * Utility class to display message and error dialogs.
     */
    public class MessageDialog {
     
        public static void showMessage(String msg) {
            JOptionPane.showMessageDialog(null, msg, JBookTrader.APP_NAME, JOptionPane.INFORMATION_MESSAGE);
        }
     
        public static void showError(String msg) {
            JOptionPane.showMessageDialog(null, msg, JBookTrader.APP_NAME, JOptionPane.ERROR_MESSAGE);
        }
     
        public static void showException(Throwable t) {
            showError(t.getMessage());
            Dispatcher.getInstance().getEventReport().report(t);
        }
    }


    second page-------------------------------------------------------------------
    package com.jbooktrader.platform.startup;
     
    import com.jbooktrader.platform.model.*;
    import com.jbooktrader.platform.util.*;
     
    import javax.swing.*;
    import java.io.*;
    import java.nio.channels.*;
     
     
    /**
     * Application starter.
     */
    public class JBookTrader {
        public static final String APP_NAME = "JBookTrader";
        public static final String VERSION = "8.07";
        public static final String RELEASE_DATE = "January 9, 2012";
        private static String appPath;
     
        /**
         * Instantiates the necessary parts of the application: the application model,
         * views, and controller.
         */
        private JBookTrader() throws JBookTraderException {
            try {
                Dispatcher.getInstance().setReporter();
                for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (Exception e) {
                throw new JBookTraderException(e);
            }
            new MainFrameController();
        }
     
        /**
         * Starts JBookTrader application.
         *
         * @param args
         */
        public static void main(String[] args) {
            try {
                File file = new File(System.getProperty("user.home"), APP_NAME + ".tmp");
                FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
     
                if (channel.tryLock() == null) {
                    MessageDialog.showMessage(APP_NAME + " is already running.");
                    return;
                }
     
                if (args.length != 1) {
                    String msg = "Exactly one argument must be passed. Usage: JBookTrader <JBookTraderDirectory>";
                    throw new JBookTraderException(msg);
                }
                appPath = args[0];
                new JBookTrader();
            } catch (Throwable t)
            {
                MessageDialog.showException(t);
            }
        }
     
        public static String getAppPath() {
            return appPath;
        }
     
    }


    My program arguments are on the file location and

    vm argumnets are

    -Xmx256M


    any help??

    Thank you!!!!
    Last edited by pbrockway2; April 14th, 2013 at 07:23 PM. Reason: code tags added


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Can somone please check my code???

    Hi rob28, welcome to the forums!

    I've added "code tags" to your post. The idea is that you put [code] at the start of a section of code and [/code] at the end. That way the forum software will properly format the code and it'll be readable.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can somone please check my code???

    Quote Originally Posted by pbrockway2 View Post
    Hi rob28, welcome to the forums!

    I've added "code tags" to your post. The idea is that you put [code] at the start of a section of code and [/code] at the end. That way the forum software will properly format the code and it'll be readable.


    noted...Thank you!

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Can somone please check my code???

    Exception in thread "main" java.lang.NullPointerException
    at com.jbooktrader.platform.util.MessageDialog.showEx ception(MessageDialog.java:23)
    at com.jbooktrader.platform.startup.JBookTrader.main( JBookTrader.java:62)
    A NullPointerException occurs when you use a variable or expression as if it had a non null value (eg call a method on it) when it is really null.

    The stack trace is saying that this happens on line 23 of MessageDialog.java, and what you have to do is find the variable or expression that is null. Guessing that problem occurs in the showException() method (I could be wrong) you would use System.out.println() to examine the values of variables and expressions you are "dereferencing" with method calls:

    public static void showException(Throwable t) {
        System.out.println("At showException t=" + t);
        showError(t.getMessage());
        System.out.println("Dispatcher instance is " + Dispatcher.getInstance());
        System.out.println("Event report is " + Dispatcher.getInstance().getEventReport());
        Dispatcher.getInstance().getEventReport().report(t);
    }

    Once you have found out which thing is null you need to go back through your code to where you thought you had given it a non null value and figure out why that didn't happen.

    ---

    If I'm wrong in my guess, say which line 23 really is. But the approach remains the same: use System.out.println() to examine everything that might possibly be null, then go back through your code to see how come it ended up null.
    Last edited by pbrockway2; April 14th, 2013 at 07:38 PM. Reason: typo in code

Similar Threads

  1. Pls check my code
    By javamonkey30 in forum Loops & Control Statements
    Replies: 12
    Last Post: March 18th, 2013, 02:26 PM
  2. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 06:43 AM
  3. Can Somebody check this code?
    By manager00104 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: January 30th, 2012, 10:27 AM
  4. Please check the code for the errors
    By nrao in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 16th, 2010, 04:37 PM
  5. Check this code out
    By jwill22 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 11th, 2010, 08:34 PM