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;
    }

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.

could you post the whole error message

could you post the whole error message

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

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

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);

Thank you very very very much!:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.