我创建了两个活动,我希望在5秒后切换它们。
第一个活动按预期午餐,但在5秒后我收到错误:The application has stopped unexpectedly.
我的包名为com.example.thebasics
,它包含两个类:
package com.example.thebasics;
import android.app.Activity;
import android.os.Bundle;
public class menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
和
package com.example.thebasics;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread logoTimer = new Thread(){
public void run(){
try{
sleep(5000);
Intent menuIntent = new Intent("com.example.thebasics.MENU");
startActivity(menuIntent);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
}; // end of Thread
logoTimer.start();
}
这是我的清单文件:
<activity
android:name=".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=".menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.thebasics.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我有两个布局文件activity_main.xml和splash.xml 我应该注意,这两项活动都很好。但与5秒的组合不起作用。
logcat的:
02-14 19:16:10.853: E/AndroidRuntime(274): FATAL EXCEPTION: Thread-8
02-14 19:16:10.853: E/AndroidRuntime(274): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.thebasics.menu }
02-14 19:16:10.853: E/AndroidRuntime(274): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
02-14 19:16:10.853: E/AndroidRuntime(274): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
02-14 19:16:10.853: E/AndroidRuntime(274): at android.app.Activity.startActivityForResult(Activity.java:2817)
02-14 19:16:10.853: E/AndroidRuntime(274): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
02-14 19:16:10.853: E/AndroidRuntime(274): at android.app.Activity.startActivity(Activity.java:2923)
02-14 19:16:10.853: E/AndroidRuntime(274): at com.example.thebasics.MainActivity$1.run(MainActivity.java:18)
02-14 19:16:11.554: I/ARMAssembler(58): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x35ea20:0x35eadc] in 402548 ns
02-14 19:16:13.194: I/Process(274): Sending signal. PID: 274 SIG: 9
02-14 19:16:13.214: I/ActivityManager(58): Process com.example.thebasics (pid 274) has died.
02-14 19:16:13.224: W/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44f76318
02-14 19:20:50.880: D/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
: E/(): Device disconnected: 1
: E/(): Device disconnected
答案 0 :(得分:1)
班级名称应为小写,如下所示:
Intent menuIntent = new Intent("com.example.thebasics.menu");
另外在您的Androidmanifest.xml中,您遇到了同样的问题,并且DEFAULT被拼错了
<intent-filter>
<action android:name="com.example.thebasics.menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
答案 1 :(得分:0)
修复拼写错误(清单中的默认值)
尝试使用构建器Intent(Context packageContext,Class cls)来创建intent。在你的情况下:
Intent menuIntent = new Intent(this, menu.class);