繁体   English   中英

android:不幸的是[app_name]已停止

[英]android : Unfortunately [app_name] has stopped

LOGCAT错误:

Logcat

*****01-27 11:56:11.307: D/dalvikvm(1040): GC_FOR_ALLOC freed 51K, 5% free 2596K/2724K, paused 34ms, total 36ms

01-27 11:56:11.337: I/dalvikvm-heap(1040): Grow heap (frag case) to 5.608MB for 3145744-byte allocation

01-27 11:56:11.387: D/dalvikvm(1040): GC_FOR_ALLOC freed 2K, 3% free 5666K/5800K, paused 50ms, total 50ms

01-27 11:56:12.108: D/dalvikvm(1040): GC_FOR_ALLOC freed <1K, 3% free 5666K/5800K, paused 24ms, total 26ms

01-27 11:56:12.117: I/dalvikvm-heap(1040): Grow heap (frag case) to 6.939MB for 1398800-byte allocation

01-27 11:56:12.167: D/dalvikvm(1040): GC_FOR_ALLOC freed <1K, 2% free 7032K/7168K, paused 47ms, total 47ms

01-27 11:56:12.387: D/gralloc_goldfish(1040): Emulator without GPU emulation detected.

01-27 11:56:17.229: W/dalvikvm(1040): threadid=11: thread exiting with uncaught exception (group=0x41465700)

01-27 11:56:17.249: E/AndroidRuntime(1040): FATAL EXCEPTION: Thread-90

01-27 11:56:17.249: E/AndroidRuntime(1040): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=Splash.this,MainActivity.class }

01-27 11:56:17.249: E/AndroidRuntime(1040):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)

01-27 11:56:17.249: E/AndroidRuntime(1040):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)

01-27 11:56:17.249: E/AndroidRuntime(1040):     at android.app.Activity.startActivityForResult(Activity.java:3390)

01-27 11:56:17.249: E/AndroidRuntime(1040):     at android.app.Activity.startActivityForResult(Activity.java:3351)

01-27 11:56:17.249: E/AndroidRuntime(1040):     at android.app.Activity.startActivity(Activity.java:3587)

01-27 11:56:17.249: E/AndroidRuntime(1040):     at android.app.Activity.startActivity(Activity.java:3555)

01-27 11:56:17.249: E/AndroidRuntime(1040):     at com.example.timepass.Splash$1.run(Splash.java:35)

01-27 11:56:19.957: I/Choreographer(1040): Skipped 91 frames!  The application may be doing too much work on its main thread.**

01-27 12:01:17.377: I/Process(1040): Sending signal. PID: 1040 SIG: 9***

我的应用程序名称是timepass下面的文件是MainActivity.java

package com.example.timepass;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;



public class MainActivity extends Activity {


int counter;
Button add, sub;
TextView Display;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add= (Button) findViewById(R.id.badd);
sub=(Button) findViewById(R.id.bsub);
Display=(TextView) findViewById(R.id.tvdisplay);
add.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
Display.setText("Your total is " + counter);


}
});

sub.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
Display.setText("Your 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;
}

}

下面的文件是activity_main.xml,它被重新实现为上面的文件MainActivity.java

文件名是activity_main.xml

<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=".MainActivity" 
android:background="@drawable/pic_two">"

<Button
android:id="@+id/badd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvdisplay"
android:layout_alignTop="@+id/bsub"
android:text="@string/but1"
android:textSize="20sp" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvdisplay"
android:layout_alignRight="@+id/tvdisplay"
android:text="@string/hello_world"
android:textSize="@dimen/asa" />

<TextView
android:id="@+id/tvdisplay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:gravity="center"
android:text="@string/str1"
android:textColor="@layout/activity_main"
android:textSize="30sp" />

<Button
android:id="@+id/bsub"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/tvdisplay"
android:layout_below="@+id/tvdisplay"
android:layout_marginRight="38dp"
android:layout_marginTop="23dp"
android:text="@string/but2"
android:textSize="20sp" />
</RelativeLayout>

然后我创建了另一个活动,在下面是Splash.java

package com.example.timepass;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Splash extends Activity 
{

@Override
protected void onCreate(Bundle tpsavedInstanceState)
    {
// TODO Auto-generated method stub
super.onCreate(tpsavedInstanceState);
setContentView(R.layout.splash);

Thread timer =new Thread()
{       
public void run()
{            
try
{
sleep(5000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent i =new Intent("Splash.this,MainActivity.class");
startActivity(i);
}
} 

};

timer.start(); 
}

}

然后我创建了与Splash.java相关的Xml文件,它是splash.xml

splash.xml

<?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"     
android:background="@drawable/pic_background">

</LinearLayout>

现在,我要先运行Splash.java文件,然后再运行MainActivity.java文件,因此我在Androidmanifest.xml文件中进行了一些更改,这里是更改,并且在运行程序后出现错误“不幸的是时间传递已停止”,其中时间传递是我的应用程序名称 。 请解决这个问题

AndroidManifest.xml

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

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

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<activity
android:name="com.example.timepass.Splash"
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.timepass.MainActivity"
android:label="@string/app_name" >

</activity>

</application>

</manifest>

从此行中删除"

Intent i =new Intent("Splash.this,MainActivity.class"); 

所以它读

Intent i =new Intent(Splash.this,MainActivity.class); 

此外,您正在从后台线程开始活动,该活动不起作用。 最后替换您的代码:

 runOnUiThread(new Runnable() {
     @Override
     public void run() {
         Intent i =new Intent(Splash.this, MainActivity.class);
         startActivity(i);
     }
 });

删除双引号:

Intent i =new Intent("Splash.this,MainActivity.class");
startActivity(i);

Intent i =new Intent(Splash.this, MainActivity.class);
startActivity(i);

替换您的代码

Intent i =new Intent("Splash.this,MainActivity.class"); 

Intent i =new Intent(Splash.this,MainActivity.class);

您在撰写时错误地添加了“”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM