我的应用在更改活动时崩溃这是我的代码, 我正在关注youtube上的教程,一切看起来都像他的代码。看看你是否可以提供帮助 一切似乎都是有序的,我完全复制了一切,
清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.example.helloworld.MAINACTIVITY" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity:
package com.example.helloworld;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity {
int counter;
Button add, sub;
TextView display;
@Override
public 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() {
public void onClick(View v) {
counter++;
display.setText("Your Total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter--;
display.setText("Your Total is " + counter);
}
});
}
}
Splash.java:
package com.example.helloworld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("com.example.helloworld.MAINACTIVITY");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
Logcat:
07-19 20:35:36.068: E/AndroidRuntime(1442): FATAL EXCEPTION: Thread-74
07-19 20:35:36.068: E/AndroidRuntime(1442): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloworld.MAINACTIVITY }
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Activity.startActivityForResult(Activity.java:3190)
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Activity.startActivity(Activity.java:3297)
07-19 20:35:36.068: E/AndroidRuntime(1442): at com.example.helloworld.Splash$1.run(Splash.java:23)
答案 0 :(得分:1)
尝试更改:
Intent openStartingPoint = new Intent("com.example.helloworld.MAINACTIVITY");
要:
Intent openStartingPoint = new Intent(Splash.this, MainActivity.class);
答案 1 :(得分:-1)
我认为应用程序崩溃是因为你在intent-filter中拼错了“DEFAULT”。