0

I download this project to code a software with a TabWidget. I tried to put my activity instead of the MainActivitybut everytime, it fails. I tried to change MainActivity (where there is TRYTOCHANGEHERE) to my own activity but it doesn't work. Do I need to set special settings to make it work?

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

I start in Android so it is possible that it's a stupid thing, I take any comment!

Thanks!!!!


---EDIT---

Here is the error log :

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

My application compile and is installed, but when I launch it, it stop and I get the message 'the application has stopped unexpectedly'

The class I'm trying to launch is really basic :

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

};
castors33
  • 477
  • 10
  • 26
  • You are being extremely ambiguous.. How does it fail? Does it crash? If so what does the log say? Can we see the code for your activity and the code you are using to start it? It is impossible to say without knowing these things.. – Joel Jul 27 '12 at 21:04
  • @Joel Here I tried to put all the information I could – castors33 Jul 30 '12 at 13:21
  • 1
    Did you list .TestActivity as an activity in your android manifest.xml? – Joel Jul 30 '12 at 15:06

1 Answers1

1

Try listing

.TestActivity

as an activity in your android xml file. That should work!

Joel
  • 4,732
  • 9
  • 39
  • 54