2012-07-19 77 views
0

更改活动时,我的应用程序崩溃以下是我的代码, 我在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) 
+1

请发布与崩溃相关的logcat错误消息 – slayton 2012-07-19 20:55:31

+0

您的布局文件在哪里? – slayton 2012-07-19 20:56:34

回答

1

尝试改变:

Intent openStartingPoint = new Intent("com.example.helloworld.MAINACTIVITY"); 

要:

Intent openStartingPoint = new Intent(Splash.this, MainActivity.class); 
+0

工作,谢谢,本教程是为2.2设计的,我使用4.0.3,这可能是问题吗? – 2012-07-19 21:02:02

+0

我不确定,但我不这么认为。 4.0.3应该完全向后兼容。如果它适合你,请接受答案。 =) – kaiserphellos 2012-07-19 21:04:03

+0

当然,,,,,, – 2012-07-19 21:06:32

-1

我认为应用程序崩溃,因为你拼错在意向过滤器 “DEFAULT”。