0
07-18 04:48:22.465: E/AndroidRuntime(19105): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.liamwli.fa.yearbook/com.liamwli.fa.yearbook.Home}: java.lang.NullPointerException

That is the error I get.

I have defined the Home class in the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.liamwli.fa.yearbook"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Holo" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Home"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Holo" >
            <intent-filter>
                <action android:name="com.liamwli.fa.yearbook.HOME" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

And it only started doing this when I added the putExtras line in my main activity:

enter.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                myname = name.getText().toString();
                Intent i = new Intent("com.liamwli.fa.yearbook.HOME");
                i.putExtra("myname", myname);
                startActivity(i);       
            }
        });

So, can anyone please explain what is happening?

Liam W
  • 1,193
  • 1
  • 26
  • 46

5 Answers5

0

use this:

Intent i = new Intent(context,otherActivity.class);

context of that activity from where you want to start activity.otherActivity is the name of activity which you want to start

Zaz Gmy
  • 4,236
  • 3
  • 19
  • 30
  • what are you doing??? see this http://developer.android.com/reference/android/content/Intent.html#Intent(android.content.Context, java.lang.Class>) – Zaz Gmy Jul 18 '12 at 04:29
0

Try this once

Intent i = new Intent(MainActivity.this,Home.class);
i.putExtra("myname", myname);
startActivity(i);

And I don't think this is required in Manifest

        <intent-filter>
            <action android:name="com.liamwli.fa.yearbook.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
Nirali
  • 13,571
  • 6
  • 40
  • 53
0

change like this

Intent i = new Intent(MainActivity.this, Home.class);
i.putExtra("myname", myname);
startActivity(i);  
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
0

Try this...

Intent i = new Intent( YourActivityName.this , otherActivity.class);
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
0

Ok, I looked and it looked like I was setting a variable contents outside of the onCreate method. So that is why it wasn't working.

Liam W
  • 1,193
  • 1
  • 26
  • 46