Issue
so I started some Android programming with Java 7. I have Eclipse Juno (I think that's 4.2).
The problem is that it gives me an error "Multiple markers at this line - Syntax error on token ")", ; expected - Syntax error on token ")", ; expected
On the line with the sendMessage method. Here is the code:
public class MainActivity extends ActionBarActivity {
int counter;
Button login;
EditText username, password;
String success;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
username = (EditText)findViewById(R.id.getEmail);
password = (EditText)findViewById(R.id.getPassword);
login.setOnClickListener(new View.OnClickListener() {
public void onClick (View v) {
if(username.getText().toString().equals("admin") && password.getText().toString().equals("admin")){
success = "Successful";
counter = 0;
public void sendMessage (View view){
Intent intent = new Intent("com.example.linked1n.SCREENAFTLOG");
startActivity(intent);
};
} else {
counter++;
login.setText("Unsuccessful. Try again. " + 3-counter + " tries left.");
}
}
});
}
I haven't found a solution anywhere and I did exactly as the tutorial told me. I tried to clean the project thrice and restart eclipse/computer nothing worked.
Solution
Your calling method inside onclick is wrong so try below way :-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
username = (EditText)findViewById(R.id.getEmail);
password = (EditText)findViewById(R.id.getPassword);
login.setOnClickListener(new View.OnClickListener() {
public void onClick (View v) {
if(username.getText().toString().equals("admin") && password.getText().toString().equals("admin")){
success = "Successful";
counter = 0;
sendMessage(v);
} else {
counter++;
login.setText("Unsuccessful. Try again. " + 3-counter + " tries left.");
}
}
});
public void sendMessage (View view){
Intent intent = new Intent("com.example.linked1n.SCREENAFTLOG");
startActivity(intent);
}
Answered By - duggu