我想構建一個使用HoloEverywhere的應用程序。按照此manual中的說明導入HoloEverywhere和ActionBarSherlock。無法啓動活動ComponentInfo {... MainActivity}:java.lang.NullPointerException
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
什麼問題?
在創建時出錯了。發佈完整的代碼 –
這是完整的代碼... – David
將您的代碼發佈到org.holoeverywhere.addon.IAddonBasicAttacher.inhert。這是崩潰的地方 –