Intents --- >.<

Put your problem here if it does not fit any of the other categories.

Intents --- >.<

Postby r45k » Thu Mar 12, 2009 4:55 am

I can't seem to run the code below without crashing. I followed the tuts online about tabs exactly, and got it working until i changed one line of code to set a tab's content to a separate class. NOTE: it ran fine before i added the line that made the content a new class...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class HelloTabWidget extends TabActivity {
  2.  
  3.     @Override
  4.  
  5.         public void onCreate(Bundle savedInstanceState) {
  6.  
  7.             super.onCreate(savedInstanceState);
  8.  
  9.             setContentView(R.layout.main);
  10.  
  11.  
  12.  
  13.            final TabHost mTabHost = getTabHost();
  14.  
  15.                 mTabHost.addTab(mTabHost.newTabSpec("tab_test1")
  16.  
  17.                              .setIndicator("PROFILE").setContent(new Intent(this, Profile.class)));
  18.  
  19.                 mTabHost.addTab(mTabHost.newTabSpec("tab_test2")
  20.  
  21.                              .setIndicator("FRIENDS").setContent(R.id.textview2));
  22.  
  23.                  mTabHost.addTab(mTabHost.newTabSpec("tab_test3")
  24.  
  25.                               .setIndicator("STATS").setContent(R.id.textview3));
  26.  
  27.            
  28.  
  29.             mTabHost.setCurrentTab(0);
  30.  
  31.         }
  32.  
  33.  
  34.  
  35.        
  36.  
  37.  
  38.  
  39. }
Parsed in 0.061 seconds, using GeSHi 1.0.8.4



I don't really quite understand whats going wrong when this is basically code for code from the API demo...

I'm assuming my error has to do with this line of code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ....setContent(new Intent(this, Profile.class)));.....
Parsed in 0.077 seconds, using GeSHi 1.0.8.4





here is the profile class:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Profile extends ListActivity {
  2.  
  3.  
  4.  
  5.     @Override
  6.  
  7.     public void onCreate(Bundle savedInstanceState) {
  8.  
  9.         super.onCreate(savedInstanceState);
  10.  
  11.  
  12.  
  13.         // Use a custom layout file
  14.  
  15.         setContentView(R.layout.main2);
  16.  
  17.     }
  18.  
  19. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


and it's main2 xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
  4.  
  5.    android:layout_width="fill_parent" android:layout_height="fill_parent"
  6.  
  7.    android:orientation="vertical">
  8.  
  9.     <LinearLayout
  10.  
  11.        android:layout_width="fill_parent" android:layout_height="fill_parent"
  12.  
  13.        android:orientation="vertical">
  14.  
  15.         <TextView  
  16.  
  17.                  android:layout_width="fill_parent"
  18.  
  19.         android:layout_height="wrap_content"
  20.  
  21.                 android:text="@string/welcome"/>
  22.  
  23.     </LinearLayout>
  24.  
  25. </ScrollView>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
r45k
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 12, 2009 4:42 am

Top

Postby WarrenFaith » Fri Mar 13, 2009 12:14 pm

What does the stacktrace say? Look at you LogCat...
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby r45k » Fri Mar 13, 2009 5:09 pm

This is the first time i've actually seen the error popup....

03-13 16:09:16.909: ERROR/AndroidRuntime(265): Uncaught handler: thread main exiting due to uncaught exception
03-13 16:09:16.939: ERROR/AndroidRuntime(265): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example.tabwidget/com.android.example.tabwidget.HelloTabWidget}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.example.tabwidget/com.android.example.tabwidget.Profile}; have you declared this activity in your AndroidManifest.xml?
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2141)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2157)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.os.Handler.dispatchMessage(Handler.java:88)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.os.Looper.loop(Looper.java:123)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.ActivityThread.main(ActivityThread.java:3739)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at java.lang.reflect.Method.invokeNative(Native Method)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at java.lang.reflect.Method.invoke(Method.java:515)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at dalvik.system.NativeStart.main(Native Method)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.example.tabwidget/com.android.example.tabwidget.Profile}; have you declared this activity in your AndroidManifest.xml?
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1467)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1956)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:272)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:600)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.widget.TabHost.setCurrentTab(TabHost.java:310)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.widget.TabHost.addTab(TabHost.java:203)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at com.android.example.tabwidget.HelloTabWidget.onCreate(HelloTabWidget.java:17)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2104)
03-13 16:09:16.939: ERROR/AndroidRuntime(265): ... 11 more
r45k
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 12, 2009 4:42 am

Postby MrSnowflake » Fri Mar 13, 2009 5:20 pm

This says it all, doesn't it?!
Unable to find explicit activity class {com.android.example.tabwidget/com.android.example.tabwidget.Profile}; have you declared this activity in your AndroidManifest.xml?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby r45k » Fri Mar 13, 2009 5:23 pm

Yep! Thanks :D.

Anyway, I went back and added:


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.         <activity android:name=".Profile" android:label="Profile.Class!">
  2.  
  3.             <intent-filter>
  4.  
  5.                 <action android:name="android.intent.action.MAIN" />
  6.  
  7.                 <category android:name="android.intent.category.SAMPLE_CODE" />
  8.  
  9.             </intent-filter>
  10.  
  11.         </activity>
  12.  
  13.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

... into my manifest xml...


And now I've got this:

03-13 16:15:06.829: ERROR/AndroidRuntime(300): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'




care to explain?
r45k
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 12, 2009 4:42 am

Postby r45k » Fri Mar 13, 2009 5:28 pm

Ah! wait--- never mind, got it working!


I just started over with everything fresh...new manifest.... R.java ...etc...


works perfectly now! Thanks!
r45k
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 12, 2009 4:42 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 9 guests