Hello, I am new to android development and this is my first time using eclipse so sorry if this question sounds silly.
I have created an android application called IFMApp. I have four xml pages and 4 java classes. My application, is cleaning and building fine and will install to the emulator however when I click the app to open on emulator it outputs the message Unfortunately IFMApp has stopped.
This is a copy of the console from the last compile.
[2014-05-06 13:45:10 - IFMApp] Android Launch!
[2014-05-06 13:45:10 - IFMApp] adb is running normally.
[2014-05-06 13:45:10 - IFMApp] Performing com.pkgifm.ifmapp.MainActivity activity launch
[2014-05-06 13:45:10 - IFMApp] Automatic Target Mode: launching new emulator with compatible AVD 'em'
[2014-05-06 13:45:10 - IFMApp] Launching a new emulator with Virtual Device 'em'
[2014-05-06 13:46:09 - IFMApp] New emulator found: emulator-5554
[2014-05-06 13:46:09 - IFMApp] Waiting for HOME ('android.process.acore') to be launched...
[2014-05-06 13:48:38 - IFMApp] HOME is up on device 'emulator-5554'
[2014-05-06 13:48:38 - IFMApp] Uploading IFMApp.apk onto device 'emulator-5554'
[2014-05-06 13:48:40 - IFMApp] Installing IFMApp.apk...
[2014-05-06 13:49:54 - IFMApp] Success!
[2014-05-06 13:49:55 - IFMApp] Starting activity com.pkgifm.ifmapp.MainActivity on device emulator-5554
and this is the logcat
05-06 09:08:38.916: E/AndroidRuntime(1243): FATAL EXCEPTION: main
05-06 09:08:38.916: E/AndroidRuntime(1243): Process: com.pkgifm.ifmapp, PID: 1243
05-06 09:08:38.916: E/AndroidRuntime(1243): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pkgifm.ifmapp/com.pkgifm.ifmapp.MainActivity}: java.lang.NullPointerException
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2195)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2245)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.ActivityThread.access$800(ActivityThre ad.java:135)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1196)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.os.Handler.dispatchMessage(Handler.java:10 2)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.os.Looper.loop(Looper.java:136)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.ActivityThread.main(ActivityThread.jav a:5017)
05-06 09:08:38.916: E/AndroidRuntime(1243): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 09:08:38.916: E/AndroidRuntime(1243): at java.lang.reflect.Method.invoke(Method.java:515)
05-06 09:08:38.916: E/AndroidRuntime(1243): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:779)
05-06 09:08:38.916: E/AndroidRuntime(1243): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:595)
05-06 09:08:38.916: E/AndroidRuntime(1243): at dalvik.system.NativeStart.main(Native Method)
05-06 09:08:38.916: E/AndroidRuntime(1243): Caused by: java.lang.NullPointerException
05-06 09:08:38.916: E/AndroidRuntime(1243): at com.pkgifm.ifmapp.MainActivity.onCreate(MainActivi ty.java:16)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.Activity.performCreate(Activity.java:5 231)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1087)
05-06 09:08:38.916: E/AndroidRuntime(1243): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2159)
05-06 09:08:38.916: E/AndroidRuntime(1243): ... 11 more
--- Update ---
This is my activity_main xml
<TextView android:id="@+id/txtTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="30dp" android:text="@string/welcome_to_the_ifm_app" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/txtMain" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/txtTitle" android:layout_marginTop="40dp" android:text="@string/please_click_on_the_options_available" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/txtCheck" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtMain" android:layout_centerHorizontal="true" android:layout_marginTop="120dp" android:text="@string/click_for_vehicle_checklist" android:textAppearance="?android:attr/textAppearanceMedium" /> <Button android:id="@+id/btnCheck" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtCheck" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:text="@string/checklist" /> <TextView android:id="@+id/txtDock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/please_click_for_engineers_docket" android:textAppearance="?android:attr/textAppearanceMedium" /> <Button android:id="@+id/btnDock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtDock" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:text="@string/docket" /> <TextView android:id="@+id/txtDOCare" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btnDock" android:layout_centerHorizontal="true" android:layout_marginTop="90dp" android:text="@string/please_click_for_duty_of_care" android:textAppearance="?android:attr/textAppearanceMedium" /> <Button android:id="@+id/btnDOCare" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtDOCare" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:text="@string/duty_of_care" />
and this is the java class for it
public class MainActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnHome = (Button)findViewById(R.id.btnHome); btnHome.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(),MainActivity.class); startActivityForResult(myIntent, 0); } }); } }
and this is the android manifest
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.pkgifm.ifmapp.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> <activity android:name=".Checklist"></activity> <activity android:name=".Docket"></activity> <activity android:name=".DutyOfCare"></activity> </application> </manifest>