Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Android Application wont launch on AVD in Eclipse

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Android Application wont launch on AVD in Eclipse

    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>


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Android Application wont launch on AVD in Eclipse

    Well, it looks like you have a NullPointerException on line 16 of MainActivity. What are the values of every variable on that line when the code is running?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Android Application wont launch on AVD in Eclipse

    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)
    This is the part Kevin is referring to.
    If you don't understand my answer, don't ignore it, ask a question.

  4. The Following User Says Thank You to Norm For This Useful Post:

    KevinWorkman (May 6th, 2014)

  5. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Android Application wont launch on AVD in Eclipse

    Is that layout.xml file incomplete? I don't see a definition for btnHome or any layout containers.

Similar Threads

  1. Replies: 4
    Last Post: October 3rd, 2013, 05:25 PM
  2. [SOLVED] How to write Eclipse launch file?
    By beruska in forum Java IDEs
    Replies: 3
    Last Post: October 18th, 2011, 09:41 AM
  3. Unable to launch app of java application
    By sharmaneelam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 19th, 2010, 08:42 AM