I'm not getting a direct error in Eclipse.. but when trying to run this on my phone it doesn't open the activity and then my phone resets. I might be using the array adapter wrong.. but here's my code files:
Java File package creativecoders.periodictable;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class AM extends Activity {
private ListView amList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.am);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@Override
public void onStart() {
super.onStart();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.AM, android.R.layout.simple_list_item_1);
amList.setAdapter(adapter);
}
public void onPause() {
super.onPause();
finish();
}
public void onStop() {
super.onStop();
finish();
}
public void onDestroy() {
super.onDestroy();
finish();
}
}
XML Layout File
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
String File
<string-array name="AM">
<item> ONE </item>
<item> TWO </item>
<item> THREE </item>
</string-array>
EDIT: Log file: 04-20 23:10:07.660: D/AndroidRuntime(284): Shutting down VM 04-20 23:10:07.660: W/dalvikvm(284): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 04-20 23:10:07.670: E/AndroidRuntime(284): FATAL EXCEPTION: main 04-20 23:10:07.670: E/AndroidRuntime(284): java.lang.RuntimeException: Unable to start activity ComponentInfo{creativecoders.periodictable/creativecoders.periodictable.AM}: java.lang.NullPointerException 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Handler.dispatchMessage(Handler.java:99) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Looper.loop(Looper.java:123) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.main(ActivityThread.java:4627) 04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method) 04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521) 04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-20 23:10:07.670: E/AndroidRuntime(284): at dalvik.system.NativeStart.main(Native Method) 04-20 23:10:07.670: E/AndroidRuntime(284): Caused by: java.lang.NullPointerException 04-20 23:10:07.670: E/AndroidRuntime(284): at creativecoders.periodictable.AM.onStart(AM.java:28) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Activity.performStart(Activity.java:3781) 04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636) 04-20 23:10:07.670: E/AndroidRuntime(284): ... 11 more