无法启动活动ComponentInfo {... MainActivity}:java.lang.NullPointerException

时间:2013-05-16 06:03:08

标签: android nullreferenceexception android-holo-everywhere

我想构建一个使用HoloEverywhere的应用程序。我按照manual中的描述导入HoloEverywhere和ActionBarSherlock。

MainActivity:

import org.holoeverywhere.app.*;
import android.os.Bundle;

public class MainActivity extends Activity  {

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

的AndroidManifest.xml:

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

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="17" />

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

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

</manifest>

org.holoeverywhere.addon.IAddonBasicAttacher.inhert:

public void inhert(Collection<Class<? extends IAddon>> sourceClasses) {
    List<Class<? extends IAddon>> classes = new ArrayList<Class<? extends IAddon>>();
    for (Class<? extends IAddon> clazz : sourceClasses) {
        if (!clazz.isAnnotationPresent(Addon.class)) {
            continue;
        }
        Addon addon = clazz.getAnnotation(Addon.class);
        if (addon.inhert()) {
            classes.add(clazz);
        }
    }
    addon(classes);
}

public void inhert(IAddonAttacher<?> attacher) {
    inhert(attacher.obtainAddonsList());
}

当我想运行应用程序时,我在eclipse中遇到以下错误:

     05-15 23:26:48.132: E/AndroidRuntime(16934): FATAL EXCEPTION: main
 05-15 23:26:48.132: E/AndroidRuntime(16934):
 java.lang.RuntimeException: Unable to start activity
 ComponentInfo{com.myapp/com.myapp.MainActivity}:
 java.lang.NullPointerException 05-15 23:26:48.132:
 E/AndroidRuntime(16934):   at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
 05-15 23:26:48.132: E/AndroidRuntime(16934):   at
 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
 05-15 23:26:48.132: E/AndroidRuntime(16934):   at
 android.app.ActivityThread.access$600(ActivityThread.java:130) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
 05-15 23:26:48.132: E/AndroidRuntime(16934):   at
 android.os.Handler.dispatchMessage(Handler.java:99) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 android.os.Looper.loop(Looper.java:137) 05-15 23:26:48.132:
 E/AndroidRuntime(16934):   at
 android.app.ActivityThread.main(ActivityThread.java:4745) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 java.lang.reflect.Method.invokeNative(Native Method) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 java.lang.reflect.Method.invoke(Method.java:511) 05-15 23:26:48.132:
 E/AndroidRuntime(16934):   at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
 05-15 23:26:48.132: E/AndroidRuntime(16934):   at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 dalvik.system.NativeStart.main(Native Method) 05-15 23:26:48.132:
 E/AndroidRuntime(16934): Caused by: java.lang.NullPointerException
 05-15 23:26:48.132: E/AndroidRuntime(16934):   at
 org.holoeverywhere.addon.IAddonBasicAttacher.inhert(IAddonBasicAttacher.java:89)
 05-15 23:26:48.132: E/AndroidRuntime(16934):   at
 org.holoeverywhere.app.Activity.onCreate(Activity.java:247) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 com.myapp.MainActivity.onCreate(MainActivity.java:10) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 android.app.Activity.performCreate(Activity.java:5008) 05-15
 23:26:48.132: E/AndroidRuntime(16934):     at
 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
 05-15 23:26:48.132: E/AndroidRuntime(16934):   at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
 05-15 23:26:48.132: E/AndroidRuntime(16934):   ... 11 more

有什么问题?

2 个答案:

答案 0 :(得分:0)

更改清单活动启动包名称是根包

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

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

答案 1 :(得分:0)

好的,对不起,这是HoloEverywhere的一个错误。

https://github.com/Prototik/HoloEverywhere/issues/447