2

I have imported all classes.

Here at sendMessage i recieve the error: void is an invalid type of the variable sendMessage.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    public void sendMessage(View view){

    }
}

1 Answer 1

2

You must not declare a method within another method. Close the curly bracket of onCreate before starting to declare the sendMessage method.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}// close onCreate method first

public void sendMessage(View view){
}

A java class is structured like this:

  • package
    • class
      • field
      • method
        • no method declaration allowed within another method
      • (inner classes)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.