Using Android Studio to build a Samsung Gear Fit Dialog. I have an issue with this block of code. It seems to fail when I mListView uses the .setAdapter. There is a warning when I pass the demo_list into the mListView on initialization. So something may be wrong with this demo_list. I'm new to android so I'm not sure about a few things. The code base I am using has several layout files. I put the list view in the root_layout.xml the error referencing the demo_list goes away when I define the list in root_layout but it also goes away in other layout files.
So the problem is even when I define the demo_list the app crashes on initial load app crashes when using the setAdapter. Also when I put a break point and run it through debug there is circular logic in the findViewById method.
Samsung Gear Fit (CUP SDK) http://forum.xda-developers.com/gear-fit/development/samsung-gear-fit-sdk-available-t2872803
My repo is https://github.com/jackygrahamez/MayDay
My code block in 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;
}
}
}
});
Logcat
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
Based on the error logcat, and go through your HomeActivity 'onCreate()', I see that your codes:
setContentView(R.layout.welcome_screen);
and:
ListView mListView = (ListView) findViewById(R.id.demo_list);
however, there is no ListView 'R.id.demo_list' in your layout 'welcome_screen.xml', instead ListView 'R.id.demo_list' is defined in your layout 'fragment_type_simple.xml'.
So if layout 'fragment_type_simple.xml' is your HomeActivity UI, then you should replace:
setContentView(R.layout.welcome_screen);
with:
setContentView(R.layout.fragment_type_simple);
otherwise you should add ListView with id 'demo_list' in your layout 'welcome_screen.xml'.
Hope this is clear!