Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Intent fails to start

I'm attempting to start an intent with the following code:

@Override
public void onClick(View v) {
    switch(v.getId())
    {
    case R.id.buttonEvaluate:
        evaluateAnswer();
        break;
    case R.id.buttonHelpMe:
        Intent intent = new Intent(this, HelpMenuActivity.class);
        startActivity(intent);
        break;
    }
}

However the app crashes every time. If I change HelpMenuActivity to another activity, it works just fine. I deleted and recreated the HelpMenuActivity and stripped everything out of the code files...

XML Layout:

 < ?xml version="1.0" encoding="utf-8"?>
 < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 < /RelativeLayout>

And HelpMenuActivity.java:

import android.app.Activity; import android.os.Bundle;

public class HelpMenuActivity extends Activity {
@Override
   public void onCreate(Bundle savedInstanceState){
    this.setContentView(R.layout.activity_help_menu);
    super.onCreate(savedInstanceState);
   }
}

I've tried changing R.layout.activity_help_menu to another layout that works, and it still crashes.

like image 580
S Grimminck Avatar asked Dec 06 '25 20:12

S Grimminck


2 Answers

Make sure you add the new Activity to your AndroidManifest.xml file or it will crash on you every time.

Within the applicationa block, you need to add something that looks like this:

<activity
        android:name="com.packagename.HelpMenuActivity"
        android:label="@string/app_name" >
    </activity>
like image 114
SBerg413 Avatar answered Dec 09 '25 20:12

SBerg413


Did you declare the HelpMenuActivity in the android manifest?

like image 45
elimirks Avatar answered Dec 09 '25 19:12

elimirks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!