Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不幸的是,android已经停止了_Android_Eclipse_Android Intent_Android Emulator - Fatal编程技术网

不幸的是,android已经停止了

不幸的是,android已经停止了,android,eclipse,android-intent,android-emulator,Android,Eclipse,Android Intent,Android Emulator,我是新来的,我想找到一些解决方案。每次我点击登录按钮时,我总是会出现一个错误,提示“不幸, 安卓停止了“我想不出我有什么错误 First.java firstlayout.xml secondlayout.xml thirdlayoutadmin.xml 您不应该使用System.exit(0)。改用finish()。你能提供你在应用程序意外退出时收到的logcat消息吗?您可以在Eclipse中标题为“Logcat”的窗口中看到这些消息,也可以通过在终端中键入“adb Logcat”来收集这些

我是新来的,我想找到一些解决方案。每次我点击登录按钮时,我总是会出现一个错误,提示“不幸, 安卓停止了“我想不出我有什么错误

First.java

firstlayout.xml

secondlayout.xml

thirdlayoutadmin.xml


您不应该使用
System.exit(0)。改用
finish()

你能提供你在应用程序意外退出时收到的logcat消息吗?您可以在Eclipse中标题为“Logcat”的窗口中看到这些消息,也可以通过在终端中键入“adb Logcat”来收集这些消息。欢迎使用stackoverflow!只发布有问题的代码,而不是整个应用程序。同时,如果您可以发布stacktrace,也可以帮助您。您为什么要使用system.exit(0)?不要试图“退出”你的应用程序。让Android负责应用程序管理和导航。如果你真的想退出屏幕,那么调用finish()方法关闭当前活动
    package com.example.android;

            import android.os.Bundle;
            import android.app.Activity;
            import android.view.Menu;
            import android.view.View;
            import android.view.View.OnClickListener;
            import android.widget.*;
            import android.content.Intent;




            public class First extends Activity {

                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.firstlayout);
                    Button admin = (Button) findViewById (R.id.admin);
                    admin.setOnClickListener(new OnClickListener(){




                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Intent it = new Intent (First.this, Secondadmin.class);
                    startActivity(it);
                    System.exit(0);

                }

                    });

                    Button sec = (Button) findViewById(R.id.sec);
                    sec.setOnClickListener(new OnClickListener(){

                        public void onClick(View arg0) {
                            // TODO Auto-generated method stub
                        Intent is = new Intent(First.this, Secondsec.class);
                            startActivity(is);
                            System.exit(0);
                        }

                    });

                    Button stock = (Button) findViewById (R.id.stock);
                    stock.setOnClickListener(new OnClickListener () {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                        Intent iu= new Intent(First.this,Secondstock.class);
                            startActivity(iu);
                            System.exit(0);
                        }

                    });

                }


                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                    // Inflate the menu; this adds items to the action bar if it is present.
                    getMenuInflater().inflate(R.menu.first, menu);
                    return true;
                }

            }
        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout
            android:id="@+id/widget32"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            xmlns:android="http://schemas.android.com/apk/res/android">
        <Button
            android:id="@+id/admin"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:text="ADMIN" />
        <Button
            android:id="@+id/sec"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:text="SECRETARY" />
        <Button
            android:id="@+id/stock"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:text="CHECKERS" />
        </LinearLayout>
 package com.example.android;



        import android.app.Activity;
        import android.app.AlertDialog;
        import android.os.Bundle;
        import android.widget.Button;

        import android.view.View.OnClickListener;
        import android.view.View;
        import android.content.DialogInterface;
        import android.content.Intent;


        public class Secondadmin extends Activity {

            @Override
            public void onCreate(Bundle savedInstanceState){
                super.onCreate(savedInstanceState);
                setContentView(R.layout.secondlayout);

                 Button login= (Button) findViewById (R.id.login);
                    login.setOnClickListener(new OnClickListener(){

                        @Override
                        public void onClick(View arg0) {

                        // TODO Auto-generated method stub

                            {    

                                 Intent log = new Intent(Secondadmin.this, Thirdadmin.class);
                                 startActivity(log);
                            }
                        }
                        });




                Button exit = (Button) findViewById (R.id.exit);
                exit.setOnClickListener(new OnClickListener() {


                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        AlertDialog.Builder builder = new AlertDialog.Builder(Secondadmin.this);
                        builder.setMessage("Are you sure you want to exit?");

                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener () {


                            public void onClick(DialogInterface arg0, int arg1) {
                                Secondadmin.this.finish();
                                System.exit(0);
                            }
                        });

                builder.setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int arg1) {
                        dialog.cancel();
                        }
                    });
                AlertDialog alert= builder.create();
                alert.show();
                }});
                     Button back= (Button) findViewById (R.id.back);
                     back.setOnClickListener(new OnClickListener(){


                        @Override
                        public void onClick(View arg0) {
                            // TODO Auto-generated method stub
                            Intent is = new Intent (Secondadmin.this, First.class);
                             startActivity(is);
                         }
                });

        }

        }
<?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="91dp"
                android:layout_height="wrap_content"
                android:text="Password" />

            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPassword" >

                <requestFocus />
            </EditText>
            <Button 
                android:id="@+id/login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Login" />
            <Button
                android:id="@+id/back"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Back" />

            <Button
                android:id="@+id/exit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Exit" />

        </LinearLayout>
 package com.example.android;

        import android.os.Bundle;
        import android.app.Activity;
        import android.app.AlertDialog;
        import android.content.DialogInterface;
        import android.content.Intent;
        import android.widget.Button;
        import android.view.View;
        import android.view.View.OnClickListener;


        public class Thirdadmin extends Activity {

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.thirdlayoutadmin);

                Button view= (Button)findViewById(R.id.view);
                view.setOnClickListener(new OnClickListener(){

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub


                    Intent id= new Intent(Thirdadmin.this, Fourthview.class);
                    startActivity(id);

                }
            });
                Button update= (Button)findViewById(R.id.update);
                update.setOnClickListener(new OnClickListener(){

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub


                    Intent i= new Intent(Thirdadmin.this, Fourthupdate.class);
                    startActivity(i);

                }
            });

                Button add= (Button) findViewById (R.id.add);
                add.setOnClickListener(new OnClickListener(){


                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                            Intent it= new Intent(Thirdadmin.this, Fourthadmin.class);
                            startActivity(it);
                        }

                    });

                Button delete= (Button) findViewById (R.id.delete);
                delete.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        Intent t= new Intent(Thirdadmin.this, Fourthdelete.class);
                        startActivity(t);
                    }

                });
                Button exit = (Button) findViewById (R.id.exit);
                exit.setOnClickListener(new OnClickListener(){


                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        AlertDialog.Builder builder = new AlertDialog.Builder(Thirdadmin.this);
                        builder.setMessage("Are you sure you want to exit?");

                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener () {


                            public void onClick(DialogInterface arg0, int arg1) {
                                Thirdadmin.this.finish();
                                System.exit(0);
                            }
                        });

                builder.setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int arg1) {
                        dialog.cancel();
                        }
                    });

                AlertDialog alert= builder.create();
                alert.show();
                }});
                     Button back= (Button) findViewById (R.id.back);
                     back.setOnClickListener(new OnClickListener(){


                        @Override
                        public void onClick(View arg0) {
                            // TODO Auto-generated method stub
                            Intent is = new Intent (Thirdadmin.this, Secondadmin.class);
                             startActivity(is);
                         }
                });


                }   

            }
 <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <Button
                android:id="@+id/add"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:text="Add" />

            <Button
                android:id="@+id/view"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:text="View" />

            <Button
                android:id="@+id/update"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:text="Update" />

            <Button
                android:id="@+id/delete"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:text="Delete"/>

        </LinearLayout>
         <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.android.First"
                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=".Secondadmin"
                android:label="@string/app_name">
                </activity>

            <activity 
                android:name=".Secondsec"
                android:label="@string/app_name">
                </activity>
            <activity 
                android:name=".Secondstock"
                android:label="@string/app_name">
                </activity>
                <activity 
                android:name=".Thirdsec"
                android:label="@string/app_name">
                </activity>
                 <activity 
                android:name=".Thirdstock"
                android:label="@string/app_name">
                </activity>
                 <activity 
                android:name=".Thirdadmin"
                android:label="@string/app_name">
                </activity>
                <activity
                android:name=".Fourthadmin"
                android:label="@string/app_name">     
                </activity>
                <activity
                android:name=".Fourthstock"
                android:label="@string/app_name">     
                </activity>
                <activity
                android:name=".Fourthdelete"
                android:label="@string/app_name"> 
                </activity>
                <activity
                android:name=".Fourthview"
                android:label="@string/app_name">
                </activity>
        </application>

    </manifest>
04-15 02:29:54.553: W/dalvikvm(790): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-15 02:29:54.603: E/AndroidRuntime(790): FATAL EXCEPTION: main
04-15 02:29:54.603: E/AndroidRuntime(790): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android/com.example.android.Thirdadmin}: java.lang.NullPointerException
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.os.Looper.loop(Looper.java:137)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.ActivityThread.main(ActivityThread.java:5041)
04-15 02:29:54.603: E/AndroidRuntime(790):  at java.lang.reflect.Method.invokeNative(Native Method)
04-15 02:29:54.603: E/AndroidRuntime(790):  at java.lang.reflect.Method.invoke(Method.java:511)
04-15 02:29:54.603: E/AndroidRuntime(790):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-15 02:29:54.603: E/AndroidRuntime(790):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-15 02:29:54.603: E/AndroidRuntime(790):  at dalvik.system.NativeStart.main(Native Method)
04-15 02:29:54.603: E/AndroidRuntime(790): Caused by: java.lang.NullPointerException
04-15 02:29:54.603: E/AndroidRuntime(790):  at com.example.android.Thirdadmin.onCreate(Thirdadmin.java:73)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.Activity.performCreate(Activity.java:5104)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-15 02:29:54.603: E/AndroidRuntime(790):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-15 02:29:54.603: E/AndroidRuntime(790):  ... 11 more