Nick
Nick

Reputation: 2641

Android: I added another button but now the app crashes

I added another button to my app but now the app crashes on start up. Here is the code that I added in, when I block it out the app runs fine.

btnnext.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {

        startActivity(new Intent("com.com.com.addtask"));
    }
});

}

I think it might be a problem with the manifest so here is the manifest too (and this is only a playing around app so dont hassle me about the package being com.com.com)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.com.com"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET"/>

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:permission="android.permission.INTERNET">
    <activity android:name=".HelloWorldActivity"
              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=".addtask"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="com.com.com.addtask" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

</application>
</manifest>

And this might be helpful too:

05-16 21:21:55.446: E/AndroidRuntime(581): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.com.com/com.com.com.HelloWorldActivity}: java.lang.NullPointerException

Upvotes: 0

Views: 76

Answers (2)

Srikanth
Srikanth

Reputation: 164

First identify the button from xml to activity using

Button b = (Button) findViewById(R.id.btnNext);

Upvotes: 1

phalt
phalt

Reputation: 1244

Have you declared the new button that you have added within the activity?

Button btnnext = (Button)findViewById(R.id.myNewButton);

If you don't do this and set a listener it will throw the nullpointer error.

Upvotes: 4

Related Questions