Hi. so we have this tutorial, a program that we have to complete, that we have to do before attending class and I've sort of completed it except for this small error.

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
id cannot be resolved or is not a field id cannot be resolved to a variable

id thats refered to is in the Main Class:

System.out.println("###### Our Loyalty Programme ###### \n");
System.out.print("Enter Member ID >> ");
String.id = sc.nextLine();

System.out.print("Enter Name >> ");
String name = sc.nextLine();

Member member = new Member(id, name);
LoyaltyCard card = member.getCard();

Problem Description
To celebrate the 2nd anniversary of the company, ABC Kiosk is giving a free loyalty card to all its
Customers who register for its loyalty programme will be rewarded 1 point for every RM 1 spent at
the kiosk. Then, the points that have been collected by registered members can be redeemed to pay
for items bought from the kiosk.
Each member can have only one loyalty card, and the type of the loyalty card is categorised into
three categories based on the current total of the collected points.

some code for Member Class

private String memberID;
private String name;
private LoyaltyCard card;

public Member(String memberID, String name){
    this.memberID = memberID;
    this.name = name;
    card = new LoyaltyCard();

also just to inform, the main class was actualy already given we just had to do the Member Class and LoyaltyCard Cass.

Recommended Answers

All 3 Replies

You have a spurious . between String and id on line 3

to explain a bit more James' post (he's right, btw, that is your issue)

if you put String.id your compiler will go looking for a static variable called id within the String class.
Since there's no such variable, the compiler doesn't know how to deal with it.

It's not a variable in the String class you want to use, rather an instance of the String class, so remove the . operator, and it 'll work just fine.

thank you. did not notice that.

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.