0

我下载了这个项目来编写一个带有TabWidget. 我试图把我的活动而不是,MainActivity但每次都失败了。我试图将MainActivity(有 TRYTOCHANGEHER​​E 的地方)更改为我自己的活动,但它不起作用。我是否需要设置特殊设置才能使其正常工作?

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 开始,所以这可能是一件愚蠢的事情,我接受任何评论!

谢谢!!!!


- -编辑 - -

这是错误日志:

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);
    }

};
4

1 回答 1

1

尝试列出

.TestActivity

作为你的 android xml 文件中的一个活动。那应该工作!

于 2012-07-30T16:58:44.543 回答