Error to call Activity

0

I'm having trouble calling another activity . Here is the code for 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 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 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
    
asked by anonymous 23.09.2014 / 14:57

2 answers

1

You are attempting 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); 
    } 

You are also trying to point to the android.view Menu and not yours. Use the full path of your class instead of Menu.class. Something like com.example.radiosu.Menu.class probably.

    
23.09.2014 / 15:34
0

It would not be because you would not click on something "empty". Try to set the image and or button by its id, internally to onCreateView() , using onClickListener() (this is sure to work):

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

Viewing your AndroidManifest it opens in Menu, would not first open in Activity Main (the main activity, base for the others)?

    
20.01.2016 / 19:26