您好我正在开发一个Android启动器,一切都在我的faea f2上工作但是当我试图在我的faea f1和我的moto atrix 4g上运行它时,当我点击应用程序抽屉按钮时,启动器崩溃LogCat显示此错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.d4a.tobiasuil2/com.guillaumecendre.android.launcher.Main}: java.lang.NullPointerException
下面是完整的逻辑日志:
01-01 18:18:30.778: E/PhonePolicy(4746): Could not preload class for phone policy: com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback
01-01 18:18:37.237: E/Click event(4746): Home button tapped
01-01 18:18:37.837: E/AndroidRuntime(4746): FATAL EXCEPTION: main
01-01 18:18:37.837: E/AndroidRuntime(4746): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.d4a.tobiasuil2/com.guillaumecendre.android.launcher.Main}: java.lang.NullPointerException
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2102)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.ActivityThread.access$600(ActivityThread.java:133)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.os.Looper.loop(Looper.java:137)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.ActivityThread.main(ActivityThread.java:4765)
01-01 18:18:37.837: E/AndroidRuntime(4746): at java.lang.reflect.Method.invokeNative(Native Method)
01-01 18:18:37.837: E/AndroidRuntime(4746): at java.lang.reflect.Method.invoke(Method.java:511)
01-01 18:18:37.837: E/AndroidRuntime(4746): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-01 18:18:37.837: E/AndroidRuntime(4746): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-01 18:18:37.837: E/AndroidRuntime(4746): at dalvik.system.NativeStart.main(Native Method)
01-01 18:18:37.837: E/AndroidRuntime(4746): Caused by: java.lang.NullPointerException
01-01 18:18:37.837: E/AndroidRuntime(4746): at com.guillaumecendre.android.launcher.Main.doLayout(Main.java:1207)
01-01 18:18:37.837: E/AndroidRuntime(4746): at com.guillaumecendre.android.launcher.Main.onCreate(Main.java:261)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.Activity.performCreate(Activity.java:5024)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-01 18:18:37.837: E/AndroidRuntime(4746): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
01-01 18:18:37.837: E/AndroidRuntime(4746): ... 11 more
Main.java //代码是大到发布所以通过Drive:
指向它的链接https://docs.google.com/document/d/15xlQ3nZ0b1pBq82xopcq-htEWAmrRnqQDY5uX8gabqM/edit?usp=sharing
任何帮助都会很棒
提前谢谢!
D3vs4apps
答案 0 :(得分:0)
在您的代码中,您正在执行此操作:
View v = null;
cva = new CustomViewAdapter(this, 0, apps, Settings.font, Settings.font_color, Settings.font_size, Settings.icon_size, Settings.list_style, mode);
orientation = getResources().getConfiguration().orientation;
if (Settings.list_style == LIST_STYLE) {
lv = (ListView) v;
lv.setAdapter(cva);
您将v
设置为null
,然后将其转换为ListView
(什么都不做),然后您尝试访问null的setAdapter
方法变量,因此,您的NullPointerException
就行1207
,即lv.setAdapter(cva);