我正在为Android创建一个应用程序,但发现错误“不幸的是我的应用程序已停止”,请帮我
AndroIDManifest .xml
<?xml version="1.0" enCoding="utf-8"?> <manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.example.techtips" 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.techblogon.activitylifecycleexample.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=".SecondActivity"> </activity> </application> </manifest>
RES /布局
layout2 .xml
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_margintop="150dp" androID:layout_gravity="center_horizontal" androID:textSize="23dp" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="This Is Second Activity" /> </linearLayout>
main.xml中
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_gravity="center_horizontal" androID:textSize="23dp" androID:layout_margintop="150dp" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="This Is Fist Activity Activity"/> <button androID:ID="@+ID/button1" androID:layout_gravity="center_horizontal" androID:layout_margintop="20dp" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text=" Second Activity " androID:onClick="startSecondActivity"/> </linearLayout>
src /com.example.techtip/
MainActivity.java
package com.example.techtips; import androID.os.Bundle; import androID.app.Activity; import androID.content.Intent; import androID.util.Log; import androID.vIEw.VIEw; import androID.Widget.Toast; public class MainActivity extends Activity { /** Called when the activity is first created. */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); Toast.makeText(this, "On Create Called In First Activity", Toast.LENGTH_LONG).show(); Log.i("FirstActivity", "InsIDe onCreate"); } @OverrIDe protected voID onStart() { // Todo auto-generated method stub super.onStart(); Toast.makeText(this, "On Start Called In First Activity", Toast.LENGTH_LONG).show(); Log.i("FirstActivity", "InsIDe onStart"); } @OverrIDe protected voID onResume() { // Todo auto-generated method stub super.onResume(); Toast.makeText(this, "On Resume Called In First Activity", Toast.LENGTH_LONG).show(); Log.i("FirstActivity", "InsIDe onResume");} @OverrIDeprotected voID onPause() { // Todo auto-generated method stub super.onPause(); Toast.makeText(this, "On Pause Called In First Activity", Toast.LENGTH_LONG).show(); Log.i("FirstActivity", "InsIDe onPause");} @OverrIDeprotected voID onStop() { // Todo auto-generated method stub super.onStop(); Toast.makeText(this, "On Stop Called In First Activity", Toast.LENGTH_LONG).show(); Log.i("FirstActivity", "InsIDe onStop");}@OverrIDeprotected voID onDestroy() { // Todo auto-generated method stub super.onDestroy(); Toast.makeText(this, "On Destroy Called In First Activity", Toast.LENGTH_LONG).show(); Log.i("FirstActivity", "InsIDe onDestroy"); } public voID startSecondActivity(VIEw V) { // create an new Intent and Start Second Activity Intent intent=new Intent(this,SecondActivity.class); startActivity(intent); }}
SecondActivity.java
package com.example.techtips; import androID.app.Activity; import androID.os.Bundle; import androID.util.Log; import androID.Widget.Toast; public class SecondActivity extends Activity{ /** Called when the activity is first created. */@OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.layout2); Toast.makeText(this, "On Create Called In Second Activity", Toast.LENGTH_LONG).show(); Log.i("SecondActivity", "InsIDe onCreate");} @OverrIDe protected voID onStart() { // Todo auto-generated method stub super.onStart(); Toast.makeText(this, "On Start Called In Second Activity", Toast.LENGTH_LONG).show(); Log.i("SecondActivity", "InsIDe onStart");} @OverrIDe protected voID onResume(){ // Todo auto-generated method stub super.onResume(); Toast.makeText(this, "On Resume Called In Second Activity", Toast.LENGTH_LONG).show(); Log.i("SecondActivity", "InsIDe onResume");} @OverrIDe protected voID onPause() { // Todo auto-generated method stub super.onPause(); Toast.makeText(this, "On Pause Called In Second Activity", Toast.LENGTH_LONG).show(); Log.i("SecondActivity", "InsIDe onPause"); } @OverrIDeprotected voID onStop() { // Todo auto-generated method stub super.onStop(); Toast.makeText(this, "On Stop Called In Second Activity", Toast.LENGTH_LONG).show(); Log.i("SecondActivity", "InsIDe onStop");} @OverrIDe protected voID onDestroy() { // Todo auto-generated method stub super.onDestroy(); Toast.makeText(this, "On Destroy Called In Second Activity", Toast.LENGTH_LONG).show(); Log.i("SecondActivity", "InsIDe onDestroy"); } }
请帮助他解决
并且还请帮助我创建像这样的简单应用程序??请帮助我
图片:i.stack.imgur.com/20iui.jpg
解决方法:
清单文件中的程序包名称不构成IMO.首先尝试纠正它们;
package="com.example.techtips"
和
<activity androID:name="com.techblogon.activitylifecycleexample.MainActivity" androID:label="@string/app_name" >
尝试将第二个更改为:
<activity androID:name=".MainActivity" androID:label="@string/app_name" >
总结 以上是内存溢出为你收集整理的java-“很遗憾,我的应用已停止”全部内容,希望文章能够帮你解决java-“很遗憾,我的应用已停止”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)