[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

my jar file won't execute because of errors in my class? but it works fine when i display in browser or compile run in textpad?

Asked by tyweed420 in Java Programming Language, New to Java Programming

Tags: pnlbase

C:\j2sdk1.4.2\bin>java -jar Calendar.jar
Exception in thread "main" java.lang.NullPointerException
        at java.util.StringTokenizer.<init>(StringTokenizer.java:146)
        at java.util.StringTokenizer.<init>(StringTokenizer.java:162)
        at hw2.labarbera.CalendarApp.parseDate(CalendarApp.java:130)
        at hw2.labarbera.CalendarApp.start(CalendarApp.java:85)
        at hw2.labarbera.CalendarApp.main(CalendarApp.java:410)

I'm getting this error when i try to create a jar file on my class. Let me explain a few things about this class. It's an applet that prints data from two text files onto the applet. It also has a main so it displays as an application. In textpoad i can run as application just fine. The same goes for in the browser.

it's in a packge hw2.labarbera

I have a manifest.......
Manifest-Version: 1.0
Main-Class: hw2.labarbera.CalendarApp
Created-By: Steve


every .class is in hw2/labarbera directory.


but when i try to execute the jar file i get this error

C:\j2sdk1.4.2\bin>java -jar Calendar.jar
Exception in thread "main" java.lang.NullPointerException
        at java.util.StringTokenizer.<init>(StringTokenizer.java:146)
        at java.util.StringTokenizer.<init>(StringTokenizer.java:162)
        at hw2.labarbera.CalendarApp.parseDate(CalendarApp.java:130)
        at hw2.labarbera.CalendarApp.start(CalendarApp.java:85)
        at hw2.labarbera.CalendarApp.main(CalendarApp.java:410)

Any ideas why?  do i need to jar the two text files as well or something? any help would be much appreciated!


==============================



package hw2.labarbera;

import java.awt.event.*;
import java.util.StringTokenizer;
import java.awt.*;
import java.applet.*;
import java.io.*;
import javax.swing.*;
import java.awt.Graphics2D;
import java.util.ArrayList;

public class CalendarApp extends Applet implements ActionListener
{

          String preferences[] = new String[3]; // holds view,fontsize,andshow type
        ArrayList dates;
        int fontsize=0;
        String view;
        String targetDate;
        String day;
        String month;
        String year;
        private Dimension area; //indicates area taken up by graphics


        //=======Buttons=======================
        Button button_month;
        Button button_week;
        Button button_day ;

        JPanel pnlDrawing;


        //Fonts==============================
         Font f;
         Font f2;

         /**
         init creates gui and adds listeners
         */

           public void init()
           {

           area = new Dimension(300,1200);
           JPanel pnlBase = new JPanel();

           pnlBase.setLayout(new BorderLayout());
           pnlDrawing = new DrawingPanel();
           pnlDrawing.setBackground(Color.white);

           JPanel buttons = new JPanel();
           buttons.setLayout(new FlowLayout());
           button_day = new Button("Show Day");
           button_week = new Button("Show Week");
           button_month = new Button("Show Month");
           buttons.add(button_day);
           buttons.add(button_week);
           buttons.add(button_month);
           pnlBase.add(buttons,BorderLayout.NORTH);
           this.setLayout(new BorderLayout());
            JScrollPane sp = new JScrollPane(pnlDrawing);

           pnlBase.add(sp,BorderLayout.CENTER);

           this.add(pnlBase,BorderLayout.CENTER);

            button_day.addActionListener(this);
            button_week.addActionListener(this);
            button_month.addActionListener(this);


            f=new Font("Arial",Font.BOLD,18);
            f2=new Font("Arial",Font.BOLD,14);


           }

         /**
         start calls 3 methods that perform the calendar actions
         */
           public void start()
           {
                getPreferences();
                parseDate();
              loadDates();

           }

         /**
         Performs the actions when one of the buttons is clicked
         */
           public void actionPerformed( ActionEvent evt)
             {

            Object action = evt.getSource();

            if(action == button_month)
            {
                        getMonth(targetDate);
                pnlDrawing.setPreferredSize(area);
                pnlDrawing.revalidate();
                      pnlDrawing.repaint();


                  }
                  else if(action == button_week)
                {
                      getWeek(targetDate);
                pnlDrawing.revalidate();
                      pnlDrawing.repaint();


                  }
                  else if(action == button_day)
                {
                     getDay(targetDate);
              pnlDrawing.revalidate();
                      pnlDrawing.repaint();


                  }
           }

         /**
         Parses date 09/30/05 to 09  30  05 into appropriate variable
         */
         private void parseDate()
         {
                   StringTokenizer tokens = new StringTokenizer(targetDate,"//");
                   String[] s = new String[3];
                   int i=0;
                   while(tokens.hasMoreTokens() )
                   {
                         s[i] = tokens.nextToken();
                         i++;
                   }

                  //learn how to do with split intsead of stringtokenizer
                  month = s[0];
                  day = s[1];
                  year = s[2];
             }

         /**
         Depending on what was read from the preferences file it will display
         */
           private void loadDates()
           {


                               if( view.equals("day"))
                               {
                                     getDay(targetDate);


                               }
                               else if(view.equals("week"))
                               {
                       getWeek(targetDate);
                               }
                               else if(view.equals("month"))
                               {
                       getMonth(targetDate);
                               }




           }

        /**
        Loads 7 days from current day into ArrayList dates to display
        */
        public void getWeek(String targetDate)
        {


             InputStream R   = getClass().getResourceAsStream("ScheduledDates");
                   if(R == null)
                   {
                 }
                 else
               {
                 try
                   {

                  String todo;
                  String line = null;
                  int count=0;
                   dates = new ArrayList();
                           BufferedReader br = new BufferedReader(new InputStreamReader(R));

                       boolean catching = false ;
                       while ((line = br.readLine()) != null)
                       {
                            if(line.equals(targetDate) )
                            {
                                                catching = true ;
                                          }

                            if (catching)
                            {
                                if (line.equals(""))
                                {
                                                      count++;
                                                }
                                dates.add(line); //add the line to arraylist until line  is |
                            }

                            if(count == 7)
                            return;
                        }



                       }
                       catch(IOException e)
                       {System.out.println("error");
                         }

                   }





            }

        /**
        Loads current day into ArrayList dates to display
        */
           public void getDay(String targetDate)
           {
                   InputStream R   = getClass().getResourceAsStream("ScheduledDates");
                   if(R == null)
                   {
                     // g.drawString("R is null",0,0);
                 }
                 else
               {
                 try
                   {

                 String todo;
                  String line = null;
                  dates = new ArrayList();
                           BufferedReader br = new BufferedReader(new InputStreamReader(R));

                       boolean catching = false ;
                       while ((line = br.readLine()) != null)
                       {
                            if(line.equals(targetDate) )
                            { catching = true ; }

                            if (catching)
                            {
                                if (line.equals(""))
                                {
                                                      return;
                                                }
                                dates.add(line); //add the line to arraylist until line  is |
                            }
                        }



                       }
                       catch(IOException e)
                       {System.out.println("error");
                         }

                   }

             }


        /**
        Loads current month into ArrayList dates to display
        */
         private void getMonth(String targetDate)
         {
                   InputStream R   = getClass().getResourceAsStream("ScheduledDates");
                                      if(R == null)
                                      {
                                        // g.drawString("R is null",0,0);
                                    }
                                    else
                                  {
                                    try
                                      {

                                     String todo;
                                     String line = null;
                                     dates = new ArrayList();
                                              BufferedReader br = new BufferedReader(new InputStreamReader(R));

                                          boolean catching = false ;
                                          while ((line = br.readLine()) != null)
                                          {
                                               if(line.equals(targetDate) )
                                               { catching = true ; }

                                               if (catching)
                                               {
                                                   if (line.equals("|"))
                                                   {
                                                                         return;
                                                                   }
                                                   dates.add(line); //add the line to arraylist until line  is |
                                               }
                                           }



                                          }
                                          catch(IOException e)
                                          {System.out.println("error");
                                            }

                   }

             }

        /**
        Loads prefferences into variables
        fontsize
        view
        current date
        */
           public void getPreferences()
           {
                                InputStream file = getClass().getResourceAsStream("Preferences");
                                  if(file == null){
                                  }
                                  else
                                  {

                                     try
                                     {
                                       String line = null;
                                             BufferedReader in = new BufferedReader(new InputStreamReader(file));
                                             line = in.readLine();
                               StringTokenizer token = new StringTokenizer(line, "|");
                               int i=0;
                               while(token.hasMoreTokens())
                               {
                                                   preferences[i] = token.nextToken();
                                                   i++;
                                             }

                             String stringfont = preferences[2];
                             fontsize = Integer.parseInt(stringfont);
                             view = preferences[1];
                             targetDate = preferences[0];


                                         }
                                         catch(IOException e)
                                         {System.out.println("error");
                                           }

                }
             }


        /**
        The drawing surface pasted onto the scrollbar
        */
        class DrawingPanel extends JPanel
                  {
                      public void paint(Graphics g)
                      {

                      //need to clear screen
                      g.setColor(Color.white);
                      g.fillRect(0,0,getWidth(),getHeight());
                      g.setColor(Color.black);

                                g.setFont(f);
                                g.drawString("Calendar Appointments",30,50);
                                g.setFont(f2);
                                int x=30;
                                int y=70;

                                for(int i=0; i < dates.size();i++)
                                {
                        g.drawString((String) dates.get(i),x,y);
                                    y+=10;

                          }

                       area.height = y +10;
                       area.width = 300;

                                       pnlDrawing.setPreferredSize(area);
                           pnlDrawing.revalidate();


                      }



                  }

         public static void main(String args[])
         {
             CalendarApp calendar = new CalendarApp();
             calendar.init();
             calendar.start();
                   JFrame frame = new JFrame("Calendar");
                   Container pane = frame.getContentPane();
             pane.add(calendar);
             frame.setSize(600,800);

             frame.show();




             }


}




[+][-]10/03/05 01:19 PM, ID: 15009540Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Java Programming Language, New to Java Programming
Tags: pnlbase
Sign Up Now!
Solution Provided By: actonwang
Participating Experts: 3
Solution Grade: A
 
[+][-]10/03/05 12:26 PM, ID: 15009074Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10/03/05 12:28 PM, ID: 15009099Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/03/05 01:21 PM, ID: 15009559Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/03/05 01:28 PM, ID: 15009607Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/03/05 01:33 PM, ID: 15009639Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/03/05 01:41 PM, ID: 15009710Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/05 12:42 AM, ID: 15279206Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92