使用Android Studio构建Samsung Gear Fit对话框。我对这段代码有疑问。当我 mListView 使用 .setAdapter 时,它似乎失败了。当我在初始化时将 demo_list 传递到 mListView 时会出现警告。所以这个 demo_list 可能有问题。我是android新手,所以我不确定一些事情。我使用的代码库有几个布局文件。我将列表视图放在 root_layout.xml 中,当我在 root_layout 中定义列表时,引用 demo_list 的错误消失了,但它在其他布局文件中也消失了。
所以问题是,即使我定义了 demo_list,应用程序在初始加载时崩溃,使用 setAdapter 时应用程序崩溃。此外,当我放置一个断点并通过调试运行它时,findViewById 方法中存在循环逻辑。
三星 Gear Fit (CUP SDK) http://forum.xda-developers.com/gear-fit/development/samsung-gear-fit-sdk-available-t2872803
我的仓库是 https://github.com/jackygrahamez/MayDay
我在 HomeActivity.java 中的代码块
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, NAMES);
ListView mListView = (ListView) findViewById(R.id.demo_list);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// S Pen SDK Demo programs
if (position == MAYDAY_CUP) {
if (mHelloCupDialog == null) {
mHelloCupDialog = new GearFitDialog(getApplicationContext());
} else {
mHelloCupDialog.finish();
mHelloCupDialog = null;
}
}
}
});
日志猫
02-07 15:11:39.059 11358-11358/com.mayday.md I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
02-07 15:11:39.079 11358-11358/com.mayday.md I/SELinux﹕ Function: selinux_android_load_priority , spota verifySig and checkHash pass. priority version is VE=SEPF_SM-G900T_4.4.2_0034
02-07 15:11:39.079 11358-11358/com.mayday.md I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts
02-07 15:11:39.079 11358-11358/com.mayday.md E/dalvikvm﹕ >>>>> Normal User
02-07 15:11:39.079 11358-11358/com.mayday.md E/dalvikvm﹕ >>>>> com.mayday.md [ userId:0 | appId:10430 ]
02-07 15:11:39.079 11358-11358/com.mayday.md D/dalvikvm﹕ Late-enabling CheckJNI
02-07 15:11:39.319 11358-11358/com.mayday.md I/PersonaManager﹕ getPersonaService() name persona_policy
02-07 15:11:39.359 11358-11358/com.mayday.md I/PersonaManager﹕ getPersonaService() name persona_policy
02-07 15:11:39.399 11358-11358/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:720 height:1280 bitmap id is 270
02-07 15:11:39.429 11358-11358/com.mayday.md I/dalvikvm-heap﹕ Grow heap (frag case) to 28.360MB for 8294416-byte allocation
02-07 15:11:39.449 11358-11358/com.mayday.md D/AndroidRuntime﹕ Shutting down VM
02-07 15:11:39.449 11358-11358/com.mayday.md W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41742da0)
02-07 15:11:39.449 11358-11358/com.mayday.md E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mayday.md, PID: 11358
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mayday.md/com.mayday.md.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mayday.md.HomeActivity.onCreate(HomeActivity.java:62)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
02-07 15:11:44.829 11358-11358/com.mayday.md I/Process﹕ Sending signal. PID: 11358 SIG: 9
02-07 15:12:29.939 12336-12336/com.mayday.md I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
02-07 15:12:29.949 12336-12336/com.mayday.md I/SELinux﹕ Function: selinux_android_load_priority , spota verifySig and checkHash pass. priority version is VE=SEPF_SM-G900T_4.4.2_0034
02-07 15:12:29.949 12336-12336/com.mayday.md I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts
02-07 15:12:29.959 12336-12336/com.mayday.md E/dalvikvm﹕ >>>>> Normal User
02-07 15:12:29.959 12336-12336/com.mayday.md E/dalvikvm﹕ >>>>> com.mayday.md [ userId:0 | appId:10431 ]
02-07 15:12:29.959 12336-12336/com.mayday.md D/dalvikvm﹕ Late-enabling CheckJNI
02-07 15:12:30.259 12336-12336/com.mayday.md I/PersonaManager﹕ getPersonaService() name persona_policy
02-07 15:12:30.309 12336-12336/com.mayday.md I/PersonaManager﹕ getPersonaService() name persona_policy
02-07 15:12:30.339 12336-12336/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:720 height:1280 bitmap id is 270
02-07 15:12:30.349 12336-12336/com.mayday.md I/dalvikvm-heap﹕ Grow heap (frag case) to 28.354MB for 8294416-byte allocation
02-07 15:12:30.369 12336-12336/com.mayday.md D/AndroidRuntime﹕ Shutting down VM
02-07 15:12:30.369 12336-12336/com.mayday.md W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41742da0)
02-07 15:12:30.379 12336-12336/com.mayday.md E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mayday.md, PID: 12336
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mayday.md/com.mayday.md.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mayday.md.HomeActivity.onCreate(HomeActivity.java:62)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
02-07 15:12:33.289 12336-12336/com.mayday.md I/Process﹕ Sending signal. PID: 12336 SIG: 9