在 Android 上从初始屏幕切换到选项卡菜单时出错
我被卡住了...
错误:
04-11 14:30:11.606: ERROR/AndroidRuntime(1012): Uncaught handler: thread Thread-8 exiting due to uncaught exception 04-11 14:30:11.616: ERROR/AndroidRuntime(1012): android.content.ActivityNotFoundException: Unable to find explicit activity class {mapa.montenegro/mapa.montenegro.TabMain}; have you declared this activity in your AndroidManifest.xml?
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivityForResult(Activity.java:2749)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivity(Activity.java:2855)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at mapa.montenegro.Main$1.run(Main.java:49)
04-11 14:30:11.606: ERROR/AndroidRuntime(1012): Uncaught handler: thread Thread-8 exiting due to uncaught exception
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): android.content.ActivityNotFoundException: Unable to find explicit activity class {mapa.montenegro/mapa.montenegro.TabMain}; have you declared this activity in your AndroidManifest.xml?
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivityForResult(Activity.java:2749)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivity(Activity.java:2855)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at mapa.montenegro.Main$1.run(Main.java:49)
主类:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
public class Main extends Activity {
//some properties..
boolean _active = true;
// time to display the splash screen in ms
int _splashTime = 3000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// thread for displaying the SplashScreen
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// print error
Log.v("InterruptedException", e.toString());
} finally {
//finish
finish();
//print
Log.v("splashTread", "Finished");
//start new activity
// Here we start the next activity, and then call finish()
// so that our own will stop running and be removed from the
// history stack.
Intent intent = new Intent();
intent.setClass(Main.this, TabMain.class); // here starts error
startActivity(intent);
finish();
}
}
};
splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
//trurn default value
return true;
}
}
//选项卡主类
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabMain extends TabActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//tabhost
TabHost tabHostMain=(TabHost) findViewById(R.layout.tab_main);
/**
* TabSpec used to create a new tab. By using TabSpec only we can able
* to setContent to the tab. By using TabSpec setIndicator() we can set
* name to tab.
*/
/** tid1 is firstTabSpec Id. Its used to access outside. */
TabSpec mapTabSpec = tabHostMain.newTabSpec("tid1");
TabSpec settingsTabSpec = tabHostMain.newTabSpec("tid1");
TabSpec homeTabSpec = tabHostMain.newTabSpec("tid1");
/** TabSpec setIndicator() is used to set name for the tab. */
/** TabSpec setContent() is used to set content for a particular tab. */
mapTabSpec.setIndicator("Map Tab Name",getResources().getDrawable(R.drawable.ico_map)).setContent(
new Intent(this, TabMap.class));
settingsTabSpec.setIndicator("Settigs Tab Name", getResources().getDrawable(R.drawable.ico_settings)).setContent(
new Intent(this, TabSettings.class));
homeTabSpec.setIndicator("Home Tab Name", getResources().getDrawable(R.drawable.ico_home)).setContent(
new Intent(this, TabHome.class));
/** Add tabSpec to the TabHost to display. */
tabHostMain.addTab(mapTabSpec);
tabHostMain.addTab(settingsTabSpec);
tabHostMain.addTab(homeTabSpec);
}
}
I am stuck...
Error:
04-11 14:30:11.606: ERROR/AndroidRuntime(1012): Uncaught handler: thread Thread-8 exiting due to uncaught exception 04-11 14:30:11.616: ERROR/AndroidRuntime(1012): android.content.ActivityNotFoundException: Unable to find explicit activity class {mapa.montenegro/mapa.montenegro.TabMain}; have you declared this activity in your AndroidManifest.xml?
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivityForResult(Activity.java:2749)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivity(Activity.java:2855)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at mapa.montenegro.Main$1.run(Main.java:49)
04-11 14:30:11.606: ERROR/AndroidRuntime(1012): Uncaught handler: thread Thread-8 exiting due to uncaught exception
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): android.content.ActivityNotFoundException: Unable to find explicit activity class {mapa.montenegro/mapa.montenegro.TabMain}; have you declared this activity in your AndroidManifest.xml?
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivityForResult(Activity.java:2749)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at android.app.Activity.startActivity(Activity.java:2855)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): at mapa.montenegro.Main$1.run(Main.java:49)
Main class:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
public class Main extends Activity {
//some properties..
boolean _active = true;
// time to display the splash screen in ms
int _splashTime = 3000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// thread for displaying the SplashScreen
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// print error
Log.v("InterruptedException", e.toString());
} finally {
//finish
finish();
//print
Log.v("splashTread", "Finished");
//start new activity
// Here we start the next activity, and then call finish()
// so that our own will stop running and be removed from the
// history stack.
Intent intent = new Intent();
intent.setClass(Main.this, TabMain.class); // here starts error
startActivity(intent);
finish();
}
}
};
splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
//trurn default value
return true;
}
}
//tab main classs
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabMain extends TabActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//tabhost
TabHost tabHostMain=(TabHost) findViewById(R.layout.tab_main);
/**
* TabSpec used to create a new tab. By using TabSpec only we can able
* to setContent to the tab. By using TabSpec setIndicator() we can set
* name to tab.
*/
/** tid1 is firstTabSpec Id. Its used to access outside. */
TabSpec mapTabSpec = tabHostMain.newTabSpec("tid1");
TabSpec settingsTabSpec = tabHostMain.newTabSpec("tid1");
TabSpec homeTabSpec = tabHostMain.newTabSpec("tid1");
/** TabSpec setIndicator() is used to set name for the tab. */
/** TabSpec setContent() is used to set content for a particular tab. */
mapTabSpec.setIndicator("Map Tab Name",getResources().getDrawable(R.drawable.ico_map)).setContent(
new Intent(this, TabMap.class));
settingsTabSpec.setIndicator("Settigs Tab Name", getResources().getDrawable(R.drawable.ico_settings)).setContent(
new Intent(this, TabSettings.class));
homeTabSpec.setIndicator("Home Tab Name", getResources().getDrawable(R.drawable.ico_home)).setContent(
new Intent(this, TabHome.class));
/** Add tabSpec to the TabHost to display. */
tabHostMain.addTab(mapTabSpec);
tabHostMain.addTab(settingsTabSpec);
tabHostMain.addTab(homeTabSpec);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在清单中声明
TabMain
活动,就像使用Main
所做的那样。您已经搞砸了 TabHost 布局。 Tab_main.xml 应如下所示:
请参阅这篇文章 。
并尝试始终显示实际的堆栈跟踪而不是旧的堆栈跟踪。
Try to declare
TabMain
activity in your manifest, as it is done withMain
.You have screwed with TabHost layout. YOu tab_main.xml should look like the following:
Please, see this article.
And try always to show the actual stacktrace instead of old one.
在manifest.xml文件中声明所有活动...就像
Declare all the activities in manifest.xml file... like