Error to call Activity

Asked

Viewed 325 times

0

I’m having trouble calling another activity. Follows code from Activity:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
}

public void entrarOnClick(View v) {
    Intent intent = new Intent(this, Menu.class);
    startActivity(intent); 
    } 

}

and the androidmanifest

<activity
        android:name=".Principal"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Menu" 
        android:label="Menu" > 
    </activity> 

follows the logcat:

09-23 14:03:21.527: E/AndroidRuntime(2464): FATAL EXCEPTION: main
09-23 14:03:21.527: E/AndroidRuntime(2464): java.lang.IllegalStateException: Could not execute method of the activity
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.view.View$1.onClick(View.java:3599)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.view.View.performClick(View.java:4204)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.view.View$PerformClick.run(View.java:17355)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.os.Handler.handleCallback(Handler.java:725)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.os.Looper.loop(Looper.java:137)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.app.ActivityThread.main(ActivityThread.java:5041)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at java.lang.reflect.Method.invokeNative(Native Method)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at java.lang.reflect.Method.invoke(Method.java:511)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at dalvik.system.NativeStart.main(Native Method)
09-23 14:03:21.527: E/AndroidRuntime(2464): Caused by: java.lang.reflect.InvocationTargetException
09-23 14:03:21.527: E/AndroidRuntime(2464):     at java.lang.reflect.Method.invokeNative(Native Method)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at java.lang.reflect.Method.invoke(Method.java:511)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.view.View$1.onClick(View.java:3594)
09-23 14:03:21.527: E/AndroidRuntime(2464):     ... 11 more
09-23 14:03:21.527: E/AndroidRuntime(2464): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.radiosu/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.app.Activity.startActivityForResult(Activity.java:3370)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.app.Activity.startActivityForResult(Activity.java:3331)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.app.Activity.startActivity(Activity.java:3566)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at android.app.Activity.startActivity(Activity.java:3534)
09-23 14:03:21.527: E/AndroidRuntime(2464):     at com.example.radiosu.Principal.entrarOnClick(Principal.java:32)
09-23 14:03:21.527: E/AndroidRuntime(2464):     ... 14 more
  • 3

    Welcome to Stackoverflow. What error are you having?

  • Why is there a function inside a function there? inOnClick shouldn’t be inside onCreate

  • It was a question. Missed ?. This problem has already been solved below.

  • You are trying to use another Menu class instead of your own. You see Menu.class? You are pointing to android.view.Menu instead of your Menu class. Instead of using Menu.class try to use com.seupackage.Menu.class

  • worked out now, thank you very much.

2 answers

1

He’s trying to declare a function within another function. Change your code to this:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);

}
public void entrarOnClick(View v) {
    Intent intent = new Intent(this, Menu.class);
    startActivity(intent); 
    } 

Also, you’re trying to point to the android.view Menu and not your own. Use the full path of your class instead of Menu.class. Something like com.example.radiosu.Menu.class probably.

  • as {}. When you say you’re a beginner in android programming you don’t mean beginner in general programming right?

  • detail so subtle that it passed beaten. - I will remove the comment above and then remove that. Hugs!

  • Remember to mark the answer as correct if it solved your problem and have a good day.

  • I can’t do that.. for I’m not the creator of the topic. :)

  • It was a comment for the community in general if the creator remembers to read the answers to his questions :)

  • it was a detail I hadn’t seen, but now it’s popping error message " Unfortunately, app has stopped. Thanks a lot

  • 1

    So the best thing to do is to update your question and put Logcat’s stacktrace so we can know what’s going on.

Show 2 more comments

0

It wouldn’t be because you wouldn’t click on something "empty". Try to set the image and or button by your id, internally to onCreateView(), using onClickListener() (this way is sure it will work):

  findViewById(R.id.bt_menu).setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View v)
      {
        Intent it = new Intent(this, Menu.class);
        startActivity(it);
      }
    });

Seeing your AndroidManifest it opens in Menu, not opened first in the Activity Main (the main activity, basis for the other)?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.