By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,003 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Exception in thread "main" java.lang.NullPointerException

nomad
Expert 100+
P: 664
Hi everyone;
My Class has ended and I was not able to solve this problem in time, and I would still like to solve it.
I got these error code.
Exception in thread "main" java.lang.NullPointerException
at ticketSales.TicketSales.makeEvent(TicketSales.java :185)
at ticketSales.TicketInput.main(TicketInput.java:56)

Anyway I have several Class

This one is called TransAction
Expand|Select|Wrap|Line Numbers
  1. public  class TransAction {
  2.        private TicketSales makeEvent;
  3.        private BuyerClass makeBuyer;
  4.        public TransAction(TicketSales ticket, BuyerClass buyer) {
  5.           this.makeEvent= ticket;
  6.           this.makeBuyer= buyer;
  7.        }
  8.        public TicketSales getTicket() { return makeEvent; }
  9.        public BuyerClass getBuyer() { return makeBuyer; }
  10. }
This is part of my TicketSales Class This is the main section which has all the data types . which has error code
Line 185 is this:
System.out.print("Enter Event ID Number (CL123, DL123, PL123) ==>");
id = kbd.next();

Expand|Select|Wrap|Line Numbers
  1. public class TicketSales {
  2.  
  3.     static Scanner kbd;
  4.  
  5.     public static EventClass makeEvent() {
  6.         EventClass ticket = null;
  7.  
  8.         // prompt for data
  9.         String id;
  10.         String en;
  11.         String ed;
  12.         String vt;
  13.         String sl;
  14.         double pr;
  15.  
  16.         System.out.print("Enter Event ID Number (CL123, DL123, PL123) ==>");
  17.         id = kbd.next();
  18.  
  19.         System.out.print("Enter Event Name (Concert, Dinner, Play) ==>");
  20.         en = kbd.next();
  21.  
  22.         System.out.print("Enter Event Date (05/12/2007) ==>");
  23.         ed = kbd.next();
  24.  
  25.         System.out.print("Enter Event Time (4:00pm==>");
  26.         vt = kbd.next();
  27.  
  28.         System.out.print("Enter Seatlayout (3500, 2000, 1500,==>");
  29.         sl = kbd.next();
  30.  
  31.         System.out.print("Enter Price (100.00)==>");
  32.         pr = kbd.nextDouble();
  33.  
  34.         // make an object
  35.         ticket = new EventClass(id, en, ed, vt, sl, pr);
  36.  
  37.         return ticket;
  38.     }
  39.  
  40. }// close TicketSales
This is my TicketInput
This has error code which is at
EventClass ticket = TicketSales.makeEvent();
Expand|Select|Wrap|Line Numbers
  1. class TicketInput {
  2.  
  3.     public static void main(String args[]) {
  4.  
  5.         // make array list object
  6.  
  7.         ArrayList<EventClass> arlist = new ArrayList<EventClass>();
  8.         arlist.add(new EventClass("CL123", "Concert", "05/12/2007", "12:00pm", "3500 Seats", 55.00));
  9.         arlist.add(new EventClass("PL123", "Play", "06/14/2007", "2:00pm", "2000 Seats", 75.00));
  10.         arlist.add(new EventClass("DL123", "Dinner", "05/29/2007", "7:00pm","1500 Seats", 100.00));
  11.         //arlist.addAll((Collection<? extends EventClass>) new EventClass("DL123", "Dinner", "05/29/2007", "7:00pm", 200.00, "Dan Smith", "1234 East ST Fullerton, CA 90000", "Row 1 Seat 14, 15"));
  12.     //arlist.addAll((Collection<? extends EventClass>) new EventClass("PL123", "Play", "06/14/2007", "2:00pm", 150.00, "Jon Doe", "1234 East ST", "Row 12 Seat 18, 19"));
  13.         System.out.println(arlist);
  14.  
  15.  
  16.         // make a scanner
  17.         Scanner kbd = new Scanner(System.in);
  18.  
  19.         int choice;
  20.         System.out.println("Make a Section: ");
  21.         System.out.println("1. Enter Event ");
  22.         System.out.println("2. Enter Buyer Info ");
  23.         System.out.println("3. Print Event ");
  24.         System.out.println("4. Print Buyer Inof ");
  25.         System.out.println("5. Exit this Program ");
  26.         System.out.print("\nPlease press Enter afer each response");
  27.         System.out.println("\nEnter your choose please: ");
  28.         choice = kbd.nextInt();
  29.         kbd.nextLine();
  30.         if (choice == 1) { // if 1 is select go to makeEvent
  31.  
  32.             boolean endData = false;
  33.  
  34.             while (!endData) {
  35.                 EventClass ticket = TicketSales.makeEvent();
  36.                 arlist.add(ticket);
  37.                 System.out.println("Add More Events (Y/N)-->");
  38.  
  39.                 String ans = kbd.next();
  40.  
  41.                 if (ans.equalsIgnoreCase("N")) {
  42.                     System.out.println(ticket);
  43.                     endData = true;
  44.                 }
  45.             }// close while loop
  46.         }// close choice 1
  47. ....
Any help would be great. Each Class is it open file.

nomad
May 18 '07 #1
Share this Question
Share on Google+
12 Replies


Expert 10K+
P: 11,448
I just quickly browsed through your code but have you instantiated your 'kbd'
scanner? I couldn't find it (but I may be wrong of course).

kind regards,

Jos
May 18 '07 #2

nomad
Expert 100+
P: 664
I just quickly browsed through your code but have you instantiated your 'kbd'
scanner? I couldn't find it (but I may be wrong of course).

kind regards,

Jos
That was it Jos....
Thanks. I looked at this for about 45 mins. Looked at the arraylist and pointers.
Darn...
I wish I could turn it in some how.
He has the assignments uploading locked.

nomad
May 18 '07 #3

nomad
Expert 100+
P: 664
I just quickly browsed through your code but have you instantiated your 'kbd'
scanner? I couldn't find it (but I may be wrong of course).

kind regards,

Jos
Don't know if I should be PMs you.
need help with this part for the article.

Expand|Select|Wrap|Line Numbers
  1. for( int i=0; i<arlist.size(); i++) {
  2. PersonClass e = arlist.get( i );
  3. System.out.println(“The info  is “+e.getEmpID(), +e.getLname() );
  4. }
Can not get e.getLname() to print.
here is the top section of class
Expand|Select|Wrap|Line Numbers
  1. class PersonClass {
  2.     private String empid;
  3.     private String name;
  4.     public PersonClass(String id) {
  5.         empid = id;
  6.     }
  7.  
  8.     public PersonClass(String id, String name) {
  9.         this.empid = id;
  10.         this.name = name;
  11.     }
  12.  
  13.     public String getID() {return empid;}
  14.     public String getName() {return name;}
  15.  
  16.     public String toString() {
  17.         return "(" + empid + ", " + name + ")";
  18.     }
thanks
nomad
May 18 '07 #4

Expert 10K+
P: 11,448
Maybe it's just me again but I don't see a getLname() method in your Person class.

kind regards,

Jos
May 18 '07 #5

nomad
Expert 100+
P: 664
Maybe it's just me again but I don't see a getLname() method in your Person class.

kind regards,

Jos
Got rid of the L in getName() in the method. but it still does not work. I get an error on
The operator + is undefined for the argument type(s) String

thanks
nomad
May 21 '07 #6

Expert 10K+
P: 11,448
Got rid of the L in getName() in the method. but it still does not work. I get an error on
The operator + is undefined for the argument type(s) String

thanks
nomad
Can't be; the '+' operator is overloaded for at least one String operand. What
is the exact error diagnostic message and the relevant code?

kind regards,

Jos
May 21 '07 #7

nomad
Expert 100+
P: 664
Can't be; the '+' operator is overloaded for at least one String operand. What
is the exact error diagnostic message and the relevant code?

kind regards,

Jos
Jos
this is the only error I get.
The operator + is undefined for the argument type(s) String

Ps Im using eclipe...
+e.getName() ); is underline with red.
it has to be comma after
System.out.println("The info is "+e.getID(),
if I get rid of the comma it works.

nomad
or I could just do this
System.out.println("Event info is " + e);

But still would like to know what there is an error.
nomad
May 21 '07 #8

Expert 10K+
P: 11,448
Jos
this is the only error I get.
The operator + is undefined for the argument type(s) String

Ps Im using eclipe...
+e.getName() ); is underline with red.
it has to be comma after
System.out.println("The info is "+e.getID(),
if I get rid of the comma it works.

nomad
or I could just do this
System.out.println("Event info is " + e);

But still would like to know what there is an error.
nomad
Can you show exactly what you're trying to do? And what's that comma doing there?

kind regards,

Jos
May 21 '07 #9

nomad
Expert 100+
P: 664
Can you show exactly what you're trying to do? And what's that comma doing there?

kind regards,

Jos
would like to print id number and name.
Comma is just a seperator between id number and name
ie
ds, James R Dean.

I need to do it this way instead
System.out.println(" Id is " + e.getID());
System.out.println("Name is " + e.getName());

Thanks.
nomad
May 21 '07 #10

Expert 10K+
P: 11,448
would like to print id number and name.
Comma is just a seperator between id number and name
ie
ds, James R Dean.

I need to do it this way instead
System.out.println(" Id is " + e.getID());
System.out.println("Name is " + e.getName());

Thanks.
nomad
Just print the comma in between; it's just text:
Expand|Select|Wrap|Line Numbers
  1. System.out.println(e.getID()+", "+e.getName());
kind regards,

Jos
May 21 '07 #11

nomad
Expert 100+
P: 664
Just print the comma in between; it's just text:
Expand|Select|Wrap|Line Numbers
  1. System.out.println(e.getID()+", "+e.getName());
kind regards,

Jos
I tried that but I forgot to add the + sign before ","
darn

nomad
Thanks a million
May 21 '07 #12

Expert 10K+
P: 11,448
You're welcome. Problem solved now?

kind regards,

Jos
May 21 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.