Reputation: 21
I have strings of codes in my Main.Activity.kt
of Android studio but I keep getting the error message "Function declaration must have a name: Unresolved reference"
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(2);
displayPrice(2*5);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
Upvotes: 2
Views: 4763
Reputation: 7020
Your file has a .kt extension indicating its kotlin but only contains java code!
Either migrate it to kotlin or use a .java file for it.
Also drop the "." between "Main" and "Activity"
So you either go for:
MainActivity.java containing your java code
OR
MainActivity.kt containing kotlin code (recommended)
Upvotes: 0
Reputation: 700
You don't have displayPrice(2*5);
function so replace displayPrice(2*5);
to display(2*5);
otherwise create function with name displayPrice(int number);
Upvotes: 0
Reputation: 782
Replace (but this is not what you want) displayPrice(2*5);
with display(2*5);
(only to solve the unreferenced error, then you will see the price instead of the quantity). Also to display the price you need create the method :
private void displayPrice(int number) {
\\ do price print.
}
The methoddisplayPrice
is undeclared so that's why bad reference error appears.
Upvotes: 2