本文介绍了不幸的是,你的App已经停止了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Main package com.example.test1; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends 活动{ @覆盖 public void onCreate(Bundle savedInstanceState) { super .onCreate( savedInstanceState); setContentView(R.layout.activity_main); final 按钮changeActivityButton =(Button)findViewById(R.id.button1); changeActivityButton.setOnClickListener( new View.OnClickListener() { public void onClick(查看v) { Intent intent = new Intent(MainActivity。 this ,Second。 class ); startActivity(intent); } } ); } } 片段 < 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_horizo​​ntal_margin android:paddingRight = @ dimen / activity_horizo​​ntal_margin android:paddingTop = @ dimen / activity_vertical_margin 工具:context = com.example.test1.MainActivity $ PlaceholderFragment > < textview> android:id = @ + id / textView1 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_alignParentLeft = true android:layout_alignParentTop = true android:layout_marginTop = 15dp android:text = 名称: android:textAppearance = ?android:attr / textAppearanceMedium /> < textview> android:id = @ + id / textView2 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_alignLeft = @ + id / textView1 android:layout_below = @ + id / textView1 android:layout_marginTop = 23dp android:text = 移动: android:textAppearance = ?android:attr / textAppearanceMedium /> < edittext> android:id = @ + id / editText1 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_above = @ + id / textView2 android:layout_alignLeft = @ + id / button1 android:layout_alignParentRight = true android:ems = 10 android:inputType = textPersonName /> < Button android:id = @ + id / button1 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_below = @ + id / editText2 android:layout_centerHorizo​​ntal = true android:layout_marginTop = 124dp android:text = 按钮 /> < edittext> android:id = @ + id / editText2 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_alignLeft = @ + id / editText1 android:layout_alignRight = @ + id / editText1 android:layout_alignTop = @ + id / textView2 android:ems = 10 android:inputType = phone> < requestfocus /> < / edittext> < / edittext>< / textview>< / textview>< / relativelayout> 清单 < manifest xmlns:android = http ://schemas.android.com/apk/res/android> package = com.example.test1 android:versionCode = 1 android:versionName = 1.0> < uses-sdk> android:minSdkVersion = 18 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.example.test1.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 = com.example.test1.Second android :label = @ string / title_activity_second> < / activity> < / application> LogCat 04-29 16:30:07.188:W / ApplicationPackageManager(19765):getCSCPackageItemText() 04-29 16:30:07.239:D / AndroidRuntime (19765):关闭VM 04-29 16:30:07.239:W / dalvikvm(19765):threadid = 1:线程退出未捕获异常(组= 0x41843da0) 04-29 16: 30:07.239:E / AndroidRuntime(19765):致命异常:主 04-29 16:30:07.239:E / AndroidRuntime(19765):处理:com.example.test1,PID:19765 04-29 16:30:07.239:E / AndroidRuntime(19765):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.test1 / com.example.test1.MainActivity}:java.lang.NullPointerException 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305) 04-29 16:30:07.239:E / AndroidRuntime( 19765):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.app.ActivityThread.access $ 900(ActivityThread.java:161) 04-29 16:30:07.239:E / AndroidRuntime( 19765):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1265) 04-29 16:30:07.239:E / AndroidRuntime(19765):at android.os.Handler.dispatchMessage(Handler .java:102) 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.os.Looper.loop(Looper.java:157) 04-29 16:30 :07.239:E / AndroidRuntime(19765):在android.app.ActivityThread.main(ActivityThread.java:5356) 04-29 16:30:07.239:E / AndroidRuntime(19765):at java.lang。 reflect.Method.invokeNative(Native Method) 04-29 16:30:07.239:E / AndroidRuntime(19765):at java.lang.reflect.Method.invoke(Method.java:515) 04-29 16:30:07.239:E / AndroidRuntime(19765):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1265) 04-29 16:30:07.239: E / AndroidRuntime(19765):at com.android.internal.os.ZygoteInit.main(ZygoteInit。 java:1081) 04-29 16:30:07.239:E / AndroidRuntime(19765):at dalvik.system.NativeStart.main(Native Method) 04-29 16:30:07.239:E / AndroidRuntime(19765):引起:java.lang.NullPointerException 04-29 16:30:07.239:E / AndroidRuntime(19765):at com.example.test1.MainActivity.onCreate(MainActivity.java:20 ) 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.app.Activity.performCreate(Activity.java:5426) 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 04-29 16:30:07.239:E / AndroidRuntime(19765):at android.app.ActivityThread.performLaunchActivity( ActivityThread.java:2269) 04-29 16:30:07.239:E / AndroidRuntime(19765):... 11 more 解决方案 PlaceholderFragment> < textview> android:id = @ + id / textView1 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_alignParentLeft = true android:layout_alignParentTop = true android:layout_marginTop = 15dp android:text = 名称: android:textAppearance = ?android:attr / textAppearanceMedium /> < textview> android:id = @ + id / textView2 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_alignLeft = @ + id / textView1 android:layout_below = @ + id / textView1 android:layout_marginTop = 23dp android:text = 移动: android:textAppearance = ?android:attr / textAppearanceMedium /> < edittext> android:id = @ + id / editText1 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_above = @ + id / textView2 android:layout_alignLeft = @ + id / button1 android:layout_alignParentRight = true android:ems = 10 android:inputType = textPersonName /> < Button android:id = @ + id / button1 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_below = @ + id / editText2 android:layout_centerHorizo​​ntal = true android:layout_marginTop = 124dp android:text = 按钮 /> < edittext> android:id = @ + id / editText2 android:layout_width = wrap_content android:layout_height = wrap_content android:layout_alignLeft = @ + id / editText1 android:layout_alignRight = @ + id / editText1 android:layout_alignTop = @ + id / textView2 android:ems = 10 android:inputType = phone> < requestfocus /> < / edittext> < / edittext>< / textview>< / textview>< / relativelayout> 清单 < manifest xmlns:android = http ://schemas.android.com/apk/res/android> package = com.example.test1 android:versionCode = 1 android:versionName = 1.0> < uses-sdk> android:minSdkVersion = 18 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.example.test1.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 = com.example.test1.Second android :label = @ string / title_activity_second> < / activity> < / application> LogCat 04-29 16:30:07.188:W / ApplicationPackageManager(19765):getCSCPackageItemText() 04-29 16:30:07.239:D / AndroidRuntime (19765):关闭VM 04-29 16:30:07.239:W / dalvikvm(19765):threadid = 1:线程退出未捕获异常(组= 0x41843da0) 04-29 16: 30:07.239:E / AndroidRuntime(19765):致命异常:主 04-29 16:30:07.239:E / AndroidRuntime(19765):处理:com.example.test1,PID:19765 04-29 16:30:07.239:E / AndroidRuntime(19765):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.test1 / com.example.test1.MainActivity}:java.lang.NullPointerException 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305) 04-29 16:30:07.239:E / AndroidRuntime( 19765):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.app.ActivityThread.access 900(ActivityThread.java:161) 04- 29 16:30:07.239:E / AndroidRuntime(19765):在android.app.ActivityThread H.handleMessage(ActivityThread.java:1265) 04-29 16: 30:07.239:E / AndroidRuntime(19765):在android.os.Handler.dispatchMessage(Handler.java:102) 04-29 16:30:07.239:E / AndroidRuntime(19765):at android.os .Looper.loop(Looper.java:157) 04-29 16:30:07.239:E / AndroidRuntime(19765):在android.app.ActivityThread.main(ActivityThread.java:5356) 04-29 16:30:07.239:E / AndroidRuntime(19765):at java.lang.reflect.Method.invokeNative(Native Method) 04-29 16:30:07.239:E / AndroidRuntime(19765): at java.lang.reflect.Method.invoke(Method.java:515) 04-29 16:30:07.239:E / AndroidRuntime(19765):at com.android.internal.os.ZygoteInit Mainpackage com.example.test1;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button changeActivityButton = (Button)findViewById(R.id.button1); changeActivityButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(MainActivity.this, Second.class); startActivity(intent); } } ); }}Fragment<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.test1.MainActivity$PlaceholderFragment" > <textview> android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="15dp" android:text="Name: " android:textAppearance="?android:attr/textAppearanceMedium" /> <textview> android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="23dp" android:text="Mobile: " android:textAppearance="?android:attr/textAppearanceMedium" /> <edittext> android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView2" android:layout_alignLeft="@+id/button1" android:layout_alignParentRight="true" android:ems="10" android:inputType="textPersonName" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText2" android:layout_centerHorizontal="true" android:layout_marginTop="124dp" android:text="Button" /> <edittext> android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_alignRight="@+id/editText1" android:layout_alignTop="@+id/textView2" android:ems="10" android:inputType="phone" > <requestfocus /> </edittext></edittext></textview></textview></relativelayout>Manifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"> package="com.example.test1" android:versionCode="1" android:versionName="1.0" > <uses-sdk> android:minSdkVersion="18" 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.example.test1.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="com.example.test1.Second" android:label="@string/title_activity_second" > </activity> </application>LogCat04-29 16:30:07.188: W/ApplicationPackageManager(19765): getCSCPackageItemText()04-29 16:30:07.239: D/AndroidRuntime(19765): Shutting down VM04-29 16:30:07.239: W/dalvikvm(19765): threadid=1: thread exiting with uncaught exception (group=0x41843da0)04-29 16:30:07.239: E/AndroidRuntime(19765): FATAL EXCEPTION: main04-29 16:30:07.239: E/AndroidRuntime(19765): Process: com.example.test1, PID: 1976504-29 16:30:07.239: E/AndroidRuntime(19765): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test1/com.example.test1.MainActivity}: java.lang.NullPointerException04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.access$900(ActivityThread.java:161)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.os.Handler.dispatchMessage(Handler.java:102)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.os.Looper.loop(Looper.java:157)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.main(ActivityThread.java:5356)04-29 16:30:07.239: E/AndroidRuntime(19765): at java.lang.reflect.Method.invokeNative(Native Method)04-29 16:30:07.239: E/AndroidRuntime(19765): at java.lang.reflect.Method.invoke(Method.java:515)04-29 16:30:07.239: E/AndroidRuntime(19765): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)04-29 16:30:07.239: E/AndroidRuntime(19765): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)04-29 16:30:07.239: E/AndroidRuntime(19765): at dalvik.system.NativeStart.main(Native Method)04-29 16:30:07.239: E/AndroidRuntime(19765): Caused by: java.lang.NullPointerException04-29 16:30:07.239: E/AndroidRuntime(19765): at com.example.test1.MainActivity.onCreate(MainActivity.java:20)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.Activity.performCreate(Activity.java:5426)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)04-29 16:30:07.239: E/AndroidRuntime(19765): ... 11 more 解决方案 PlaceholderFragment" > <textview> android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="15dp" android:text="Name: " android:textAppearance="?android:attr/textAppearanceMedium" /> <textview> android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="23dp" android:text="Mobile: " android:textAppearance="?android:attr/textAppearanceMedium" /> <edittext> android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView2" android:layout_alignLeft="@+id/button1" android:layout_alignParentRight="true" android:ems="10" android:inputType="textPersonName" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText2" android:layout_centerHorizontal="true" android:layout_marginTop="124dp" android:text="Button" /> <edittext> android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_alignRight="@+id/editText1" android:layout_alignTop="@+id/textView2" android:ems="10" android:inputType="phone" > <requestfocus /> </edittext></edittext></textview></textview></relativelayout>Manifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"> package="com.example.test1" android:versionCode="1" android:versionName="1.0" > <uses-sdk> android:minSdkVersion="18" 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.example.test1.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="com.example.test1.Second" android:label="@string/title_activity_second" > </activity> </application>LogCat04-29 16:30:07.188: W/ApplicationPackageManager(19765): getCSCPackageItemText()04-29 16:30:07.239: D/AndroidRuntime(19765): Shutting down VM04-29 16:30:07.239: W/dalvikvm(19765): threadid=1: thread exiting with uncaught exception (group=0x41843da0)04-29 16:30:07.239: E/AndroidRuntime(19765): FATAL EXCEPTION: main04-29 16:30:07.239: E/AndroidRuntime(19765): Process: com.example.test1, PID: 1976504-29 16:30:07.239: E/AndroidRuntime(19765): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test1/com.example.test1.MainActivity}: java.lang.NullPointerException04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.access900(ActivityThread.java:161)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThreadH.handleMessage(ActivityThread.java:1265)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.os.Handler.dispatchMessage(Handler.java:102)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.os.Looper.loop(Looper.java:157)04-29 16:30:07.239: E/AndroidRuntime(19765): at android.app.ActivityThread.main(ActivityThread.java:5356)04-29 16:30:07.239: E/AndroidRuntime(19765): at java.lang.reflect.Method.invokeNative(Native Method)04-29 16:30:07.239: E/AndroidRuntime(19765): at java.lang.reflect.Method.invoke(Method.java:515)04-29 16:30:07.239: E/AndroidRuntime(19765): at com.android.internal.os.ZygoteInit 这篇关于不幸的是,你的App已经停止了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-15 05:39