Leider Anwendung gestoppt hat Android- Emulator genymotion

? Omar Hassan @ | Original: StackOverFlow
---

Ich bin neu in android app Entwicklung ( von gestern nur ich begonnen, android lernen ) .

Ich erhalte Nachricht in AVD gerne - leider hat aufgehört, bitte helfen Sie mir diesen Fehler zu beheben, ich will mehr in android aber angesaugt durch diesen Fehler .. plz..plz .. mir helfen, diese sove .

meine main.java ist

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.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.os.Looper.loop(Looper.java:136)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at java.lang.reflect.Method.invoke(Method.java:515)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at dalvik.system.NativeStart.main(Native Method)
03-29 21:48:16.663: E/AndroidRuntime(1395): Caused by: java.lang.NullPointerException
03-29 21:48:16.663: E/AndroidRuntime(1395):     at com.example.first.MainActivity.onCreate(MainActivity.java:38)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.Activity.performCreate(Activity.java:5231)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 21:48:16.663: E/AndroidRuntime(1395):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-29 21:48:16.663: E/AndroidRuntime(1395):     ... 11 more
03-29 22:09:36.395: D/AndroidRuntime(1448): Shutting down VM
03-29 22:09:36.395: W/dalvikvm(1448): threadid=1: thread exiting with uncaught exception (group=0xa4d6cb20)
03-29 22:09:36.395: E/AndroidRuntime(1448): FATAL EXCEPTION: main
03-29 22:09:36.395: E/AndroidRuntime(1448): Process: com.example.first, PID: 1448
03-29 22:09:36.395: E/AndroidRuntime(1448): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.MainActivity}: java.lang.NullPointerException
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.os.Looper.loop(Looper.java:136)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at java.lang.reflect.Method.invoke(Method.java:515)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at dalvik.system.NativeStart.main(Native Method)
03-29 22:09:36.395: E/AndroidRuntime(1448): Caused by: java.lang.NullPointerException
03-29 22:09:36.395: E/AndroidRuntime(1448):     at com.example.first.MainActivity.onCreate(MainActivity.java:38)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.Activity.performCreate(Activity.java:5231)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 22:09:36.395: E/AndroidRuntime(1448):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-29 22:09:36.395: E/AndroidRuntime(1448):     ... 11 more

plz .. erklären, warum ich immer so .. sag mir die Lösung

---

Top 5 Antwort

1Noob @

Sieht aus wie Sie vergessen haben, eine Tätigkeit im Manifest erklären. Fügen Sie diese auf Ihrem AndroidManifest.xml :

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

Das Protokoll zeigt, dass Sie Ihre Tätigkeit im Android manefist.xml Datei nicht registriert haben . Jede Aktivität muss in Android -Manifest-Datei, um zu arbeiten registriert werden. ( Zitat aus developers.android.com )

<activity
android:name="com.example.facebook.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>
3shayan pourvatan @

Sie NPE bekam auf der Leitung 38, das ist :

add.setOnClickListener(new View.OnClickListener()

so add null ist, und weil Sie Ihre Schaltfläche wie erklären :

add = (Button) findViewById(R.id.bt_add);

so bt_add ID nicht existiert auf activity_main, und ich denke, das XML, die Sie veröffentlichen ist fragment_main.xml oder irgendetwas anderes .

wie Sie Ihre wichtigsten Layout festlegen auf activity_main

setContentView(R.layout.activity_main);

so dass Sie müssen folgende ID in activity_main

1- bt_add

2- bt_sub

3- textView1

Daher müssen Sie, wie Sie den Code haben activity_main :

<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" >

<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" />
4Bluel3ull @

Es scheint viel einfacher Methode um ein Problem zu lösen, wie von 8/26/14 ( korrigieren Sie mich, wenn im falschen ), aber alles, was Sie tun müssen, ist in main.java Wechsel setContentView ( R.layout.activity_main ); bis zur setContentView ( R.layout.fragment_main ); nur aktualisiert, denn ich hatte das gleiche Problem ty .