Illegal start of expression?
Posted
by Fraser
on Stack Overflow
See other posts from Stack Overflow
or by Fraser
Published on 2010-06-13T17:46:44Z
Indexed on
2010/06/13
17:52 UTC
Read the original article
Hit count: 497
I'm trying to build a simple Android app that increments a number displayed every time a button is pressed, but I can't work out how to fix the "illegal start of expression" error I keep getting.
My code:
package com.clicker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Clicker extends Activity
{
private int clickerNumber = 0;
private TextView clickerText;
private Button clickerButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
clickerText = (TextView)findViewById(R.id.clickerText);
final Button clickerButton = (Button)findViewById(R.id.clickerButton);
clickerButton.setOnClickListener(new View.OnClickListener());
{
public void onClick();
{
clickerNumber = clickerNumber++;
clickerText.setText(Integer.toString(clickerNumber));
}
}
}
}
And compiler output:
compile:
[javac] Compiling 2 source files to /home/fraser/Applications/Android/Code/Clicker/bin/classes
[javac] /home/fraser/Applications/Android/Code/Clicker/src/com/clicker/Clicker.java:24: ')' expected
[javac] clickerButton.setOnClickListener(new View.OnClickListener();
[javac] ^
[javac] /home/fraser/Applications/Android/Code/Clicker/src/com/clicker/Clicker.java:26: illegal start of expression
[javac] public void onClick();
[javac] ^
[javac] /home/fraser/Applications/Android/Code/Clicker/src/com/clicker/Clicker.java:26: illegal start of expression
[javac] public void onClick();
[javac] ^
[javac] /home/fraser/Applications/Android/Code/Clicker/src/com/clicker/Clicker.java:26: ';' expected
[javac] public void onClick();
[javac] ^
[javac] /home/fraser/Applications/Android/Code/Clicker/src/com/clicker/Clicker.java:29: ';' expected
[javac] clickerText.setText(Integer.toString(clickerNumber)));
[javac] ^
[javac] 5 errors
© Stack Overflow or respective owner