Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

java - Unfortunately application has stopped android emulator genymotion

I am new to android app development( from yesterday only i started to learn android ).

I am getting message in AVD like - unfortunately has stopped ,please help me solve this error, I want learn more in android but sucked by this error.. plz..plz.. help me to sove this.

my main.java is

package com.example.first;

public class MainActivity extends Activity {


int counter = 0 ;
Button add,sub;
TextView total;
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    add = (Button) findViewById(R.id.bt_add);
    sub = (Button) findViewById(R.id.bt_sub);
    total = (TextView) findViewById(R.id.textView1);


    add.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            counter++;
            total.setText("ur total is "+ counter);

        }
    });



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }
}

}

my main.xml is

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.first.MainActivity$PlaceholderFragment" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="ur total is 0"
    android:textSize="40sp" />

    <Button
        android:id="@+id/bt_add"
        android:layout_width="250dp"
        android:layout_height="40dp"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="add one" />

    <Button
        android:id="@+id/bt_sub"
        android:layout_width="250dp"
        android:layout_height="40dp"
        android:layout_alignLeft="@+id/bt_add"
        android:layout_below="@+id/bt_add"
        android:layout_marginTop="19dp"
        android:text="sub one" />

and the log is

        03-29 21:33:13.494: D/AndroidRuntime(1256): Shutting down VM
03-29 21:33:13.494: W/dalvikvm(1256): threadid=1: thread exiting with uncaught exception (group=0xa4d6cb20)
03-29 21:33:13.494: E/AndroidRuntime(1256): FATAL EXCEPTION: main
03-29 21:33:13.494: E/AndroidRuntime(1256): Process: com.example.first, PID: 1256
03-29 21:33:13.494: E/AndroidRuntime(1256): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.MainActivity}: java.lang.NullPointerException
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.os.Looper.loop(Looper.java:136)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at java.lang.reflect.Method.invoke(Method.java:515)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at dalvik.system.NativeStart.main(Native Method)
03-29 21:33:13.494: E/AndroidRuntime(1256): Caused by: java.lang.NullPointerException
03-29 21:33:13.494: E/AndroidRuntime(1256):     at com.example.first.MainActivity.onCreate(MainActivity.java:39)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.Activity.performCreate(Activity.java:5231)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 21:33:13.494: E/AndroidRuntime(1256):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-29 21:33:13.494: E/AndroidRuntime(1256):     ... 11 more
03-29 21:34:01.629: D/dalvikvm(1310): Late-enabling CheckJNI
03-29 21:34:01.673: D/AndroidRuntime(1310): Shutting down VM
03-29 21:34:01.673: W/dalvikvm(1310): threadid=1: thread exiting with uncaught exception (group=0xa4d6cb20)
03-29 21:34:01.673: E/AndroidRuntime(1310): FATAL EXCEPTION: main
03-29 21:34:01.673: E/AndroidRuntime(1310): Process: com.example.first, PID: 1310
03-29 21:34:01.673: E/AndroidRuntime(1310): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.MainActivity}: java.lang.NullPointerException
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.os.Looper.loop(Looper.java:136)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at java.lang.reflect.Method.invoke(Method.java:515)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at dalvik.system.NativeStart.main(Native Method)
03-29 21:34:01.673: E/AndroidRuntime(1310): Caused by: java.lang.NullPointerException
03-29 21:34:01.673: E/AndroidRuntime(1310):     at com.example.first.MainActivity.onCreate(MainActivity.java:38)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.Activity.performCreate(Activity.java:5231)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 21:34:01.673: E/AndroidRuntime(1310):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-29 21:34:01.673: E/AndroidRuntime(1310):     ... 11 more
03-29 21:36:56.615: D/AndroidRuntime(1358): Shutting down VM
03-29 21:36:56.615: W/dalvikvm(1358): threadid=1: thread exiting with uncaught exception (group=0xa4d6cb20)
03-29 21:36:56.615: E/AndroidRuntime(1358): FATAL EXCEPTION: main
03-29 21:36:56.615: E/AndroidRuntime(1358): Process: com.example.first, PID: 1358
03-29 21:36:56.615: E/AndroidRuntime(1358): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.MainActivity}: java.lang.NullPointerException
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.os.Looper.loop(Looper.java:136)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at java.lang.reflect.Method.invoke(Method.java:515)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at dalvik.system.NativeStart.main(Native Method)
03-29 21:36:56.615: E/AndroidRuntime(1358): Caused by: java.lang.NullPointerException
03-29 21:36:56.615: E/AndroidRuntime(1358):     at com.example.first.MainActivity.onCreate(MainActivity.java:38)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.Activity.performCreate(Activity.java:5231)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 21:36:56.615: E/AndroidRuntime(1358):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-29 21:36:56.615: E/AndroidRuntime(1358):     ... 11 more
03-29 21:48:16.663: D/AndroidRuntime(1395): Shutting down VM
03-29 21:48:16.663: W/dalvikvm(1395): threadid=1: thread exiting with uncaught exception (group=0xa4d6cb20)
03-29 21:48:16.663: E/AndroidRuntime(1395): FATAL EXCEPTION: main
03-29 21:48:16.663: E/AndroidRuntime(1395): Process: com.example.first, PID: 1395
03-29 21:48:16.663: E/AndroidRuntime(1395): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.MainActivity}: java.lang.NullPointerException
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.ActivityThrea

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like you forgot to declare an activity in the manifest. Add this to your AndroidManifest.xml:

<activity android:label="AnotherActivity" android:name="com.somayaji.abhi.Second" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...