我下载this项目以使用TabWidget
对软件进行编码。我尝试将我的活动而不是MainActivity
,但每次都失败了。我试图将MainActivity
(其中有TRYTOCHANGEHERE)更改为我自己的活动,但它不起作用。我是否需要设置特殊设置才能使其正常工作?
Intent intent = new Intent(this, TRYTOCHANGEHERE-->MainActivity.class);
tabHost.addTab(tabHost.newTabSpec("Main")
.setIndicator("Main", res.getDrawable(R.drawable.ic_tab_main))
.setContent(intent));
Intent intent2 = new Intent(this, SetupActivity.class);
tabHost.addTab(tabHost
.newTabSpec("Setup")
.setIndicator("Setup", res.getDrawable(R.drawable.ic_tab_setup))
.setContent(intent2));
tabHost.setCurrentTab(0);
我从Android开始,所以它可能是一个愚蠢的事情,我发表任何评论!
感谢!!!!
--- --- EDIT
以下是错误日志:
07-30 08:57:14.726: E/AndroidRuntime(1865): FATAL EXCEPTION: main
07-30 08:57:14.726: E/AndroidRuntime(1865): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tablayout/com.example.tablayout.TabLayout}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.tablayout/com.example.tablayout.IMCActivity}; have you declared this activity in your AndroidManifest.xml?
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.os.Looper.loop(Looper.java:137)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-30 08:57:14.726: E/AndroidRuntime(1865): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 08:57:14.726: E/AndroidRuntime(1865): at java.lang.reflect.Method.invoke(Method.java:511)
07-30 08:57:14.726: E/AndroidRuntime(1865): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-30 08:57:14.726: E/AndroidRuntime(1865): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-30 08:57:14.726: E/AndroidRuntime(1865): at dalvik.system.NativeStart.main(Native Method)
07-30 08:57:14.726: E/AndroidRuntime(1865): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.tablayout/com.example.tablayout.IMCActivity}; have you declared this activity in your AndroidManifest.xml?
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1767)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:285)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.widget.TabHost.setCurrentTab(TabHost.java:346)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.widget.TabHost.addTab(TabHost.java:236)
07-30 08:57:14.726: E/AndroidRuntime(1865): at com.example.tablayout.TabLayout.onCreate(TabLayout.java:24)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.Activity.performCreate(Activity.java:4465)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-30 08:57:14.726: E/AndroidRuntime(1865): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-30 08:57:14.726: E/AndroidRuntime(1865): ... 11 more
我的应用程序已编译并已安装,但是当我启动它时,它会停止并收到消息“应用程序意外停止”
我试图推出的课程非常基础:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TestActivity extends Activity {
TextView hw = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
hw = new TextView(this);
hw.setText("Hello World!");
setContentView(hw);
}
};
答案 0 :(得分:1)
尝试列出
.TestActivity
作为android xml文件中的活动。这应该有效!