0

Hello! I'm trying to make a class,but an error comes up.I have also an another class named Ticket.Thanks for your help!

import java.util.*;
public class TicketPool{
   ArrayList box= new ArrayList();
   

   public void AddTickets () {
     
      box .add(new Ticket ()); 
      
     
   }
    public void DisplayTickets (){
        for (int i=0;i<box.size();i++){
            System.out.println(box.get(i));
            
           
        }
    }



    public String findTicketid(int id){    
    String b="The ticket is in the TicketPool";
    String a="The ticket isn't in the TicketPool";
        if (Ticket.getid() <= id) { //this is the error line//
            return b;
         
       }
       else return a;
    }
3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by manou324
0

You need to loop through the list and get each "Ticket" object and check its id. You can only call getId() on an object of type Ticket, not the Ticket class itself.

0

could you post the whole error message

That's the whole error message "Non static method getid()cannot be referenced from a static context"

0

You need to loop through the list and get each "Ticket" object and check its id. You can only call getId() on an object of type Ticket, not the Ticket class itself.

How can I do it? I'm sorry I'm new to Java :S

0

create a Ticket object so you can invoke the method on it
ex.

// Create two different 
// Bicycle objects from a Bicycle class
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();

// Invoke methods on 
// those objects
bike1.changeCadence(50);
bike2.changeCadence(50);

Edited by zeroliken: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.