Results 1 to 2 of 2
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post Exception in thread "main" java.lang.NullPointerException

    i have an exception in my program n i dont know where am goin wrong.Can any1 just point out where the problems is n how to go about it
    the exception looks like this;
    Exception in thread "main" java.lang.NullPointerException
    at gov.noaa.pmel.sgt.SpaceAxis.setLocationU(Unknown Source)
    at gov.noaa.pmel.sgt.swing.JPlotLayout.addData(Unknow n Source)
    at gov.noaa.pmel.sgt.swing.JPlotLayout.addData(Unknow n Source)
    at sgtTutorial.Example1.<init>(Example1.java:69)
    at sgtTutorial.Example1.main(Example1.java:118)

    and this is my code

    Java Code:
    package sgtTutorial;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.*;
    
    import gov.noaa.pmel.sgt.dm.SGTData;
    import gov.noaa.pmel.sgt.dm.SGTLine;
    import gov.noaa.pmel.sgt.dm.SimpleLine;
    import gov.noaa.pmel.sgt.dm.SGTMetaData;
    import gov.noaa.pmel.sgt.swing.JPlotLayout;
    
    import gov.noaa.pmel.util.Point2D;
    import gov.noaa.pmel.util.Range2D;
    /**
     *
     * @author  MUNYA00M
     */
    public class Example1 extends javax.swing.JFrame {
        private JPlotLayout layout_;
        /** Creates new form Example1 */
        public Example1() {
          /*
         * Create JPlotLayout instance for SGTLine data.  X and Y axes
         * are NOT time, and no image is provided.
         */
        layout_ = new JPlotLayout(false, false, false,
                                  "Trajectory data",
                                  null,false);
        /*
         * Batch changes to layout.
         */
        layout_.setBatch(true);
        /*
         * Set the titles.
         */
        layout_.setTitles("Xenon Concentration and Poisoning",
                          "Forecast",
                          "");
        /*
         * Change the title sizes from the defaults.  (0.25, 0.15)
         */
        layout_.setTitleHeightP(0.2, 0.2);
        
         /*
         * Use a BorderLayout for the JFrame and and the JPlotLayout to
         * the "Center".  Pack the frame and make it visible.
         */
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(layout_, BorderLayout.CENTER);
        pack();
        setVisible(true);
        /*
         * Read trajectory data from local file
         */
    SGTData data = readTrajectory("myXenon.txt");
        /*
         * Add the trajectory data to the plot using the data title as the
         * data description.  The description is used in the LineKey.
         */
     layout_.addData(data,getTitle());
        /*
         * Read the North Pacific hi-resolution coastline and add
         * it to the layout.  Coastlines are handled differently by
         * JPlotLayout.  Coastlines are not used to compute the X and Y
         * ranges and are always clipped to the axes.
         */
    //    SGTLine coastLine = getCoastLine("support/npac_hi_rez",120000);
    //   layout_.setCoastLine(coastLine);
        /*
         * Turn batching off.  All batched changes to the JPlotLayout will
         * now be executed.
         */
        layout_.setBatch(false);
      
        
            initComponents();
    
        }
    
        /** 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() {
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 514, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 371, Short.MAX_VALUE)
            );
    
            pack();
        }// </editor-fold>                        
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            Example1 example = new Example1();
        /*
         * Listen for window closing events and release resources
         * and exit.
         */
        example.addWindowListener(new WindowAdapter() {
                @Override
            public void windowClosing(WindowEvent event) {
              JFrame fr = (JFrame)event.getSource();
              fr.setVisible(false);
              fr.dispose();
              System.exit(0);
            }
          });
      
    
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Example1().setVisible(true);
                }
            });
        }
    
        /**
       * Read data from local file
       */
        public SGTData readTrajectory(String file) {
            
        ArrayList alist = new ArrayList(100);
        //Reader rdr = null;
        String line = null;
        double powerLevel, time;
        Point2D.Double point = null;
        boolean first = true;
        String floatName = null;
        String t,p;
        /*
         * method used to parse the trajectory information.
        */
        /*
         * Open reader and get first line
        */
        try {
            
         BufferedReader in = new BufferedReader(new FileReader(file));
         while ((line = in.readLine()) != null){      
          /*
           * Create a tokenizer and use the default "space" token
           * separator.
           */
          StringTokenizer st = new StringTokenizer(line," ");
          if (st.countTokens() >= 2){
               t= st.nextToken();
               time = Double.parseDouble(t);
               p= st.nextToken();
               powerLevel = Double.parseDouble(p);
               
               } else {
               break;
              }
    //      time = Double.parseDouble(st.nextToken());
    //      powerLevel = Double.parseDouble(st.nextToken());
          if(first) {
            first = false;
            floatName = st.nextToken();
          }
          /*
           * create point object and add to list
           */
          point = new Point2D.Double(time,powerLevel );
          alist.add(point);
          /*
           * Read the next line
           */
           line = in.readLine();
         } 
        }catch (IOException e) {
          e.printStackTrace();
        } 
         /*
         * Done reading data.  Create double arrays and load
         * data from ArrayList.
         */
         double[] xArray = new double[alist.size()];
         double[] yArray = new double[alist.size()];
         Iterator it = alist.iterator();
         int i=0;
         while(it.hasNext()) {
         point = (Point2D.Double)it.next();
         xArray[i] = point.x;
         yArray[i] = point.y;
         i++;
        }
        /*
         * Create SimpleLine using the float number as part of the name.
         */
        SimpleLine data = new SimpleLine(xArray,
                                         yArray,
                                         "Float " + floatName);
        data.setId(file);
    
        /*
         * Create metadata object for X and Y axes.
         */
        SGTMetaData meta = new SGTMetaData("Time",
                                           "Hours (x axis)",
                                           false,
                                           false);
    
        data.setXMetaData(meta);
        meta = new SGTMetaData("Powere Level",
                               "percentage",
                               false,
                               false);
        data.setYMetaData(meta);
        
      return data; 
        
       
     }
        
          // Variables declaration - do not modify                     
        // End of variables declaration                   
    
    }
    your help will be highly appreciated

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    this line
    Java Code:
        layout_ = new JPlotLayout(false, false, false,
                                  "Trajectory data",
                                  null,false);
    is causing a NPE somewhere inside of this JPlotLayout class. probably because you are providing null as an argument.

Similar Threads

  1. Replies: 15
    Last Post: 10-12-2010, 05:51 PM
  2. Replies: 12
    Last Post: 10-05-2008, 06:52 AM
  3. Replies: 3
    Last Post: 01-29-2008, 01:37 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 AM

Posting Permissions

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