Tabhost.addtab with intent crashes (solved)

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Tabhost.addtab with intent crashes (solved)

Postby harryh99 » Tue Jan 19, 2010 9:41 pm

Hi,

i feel kind of bad that I have to ask this question, because the problem seems easy to solve. For quite a few hours I´m trying to create an app that opens 3 tabs, where one uses an intent to launch another activity (in my example list1).
If I launch just list1 (as a normal activity) it runs normal. If I click the tab that should run list1 the application crashes.
I used exactly the code from the api-demo Tablist3 of the sdk and it crashed. I was able to run the example Tablist3 without problems (but it´s the same code??).
Maybe somebody sees what I did wrong.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ...
  3.  
  4. public class Lotto extends TabActivity {
  5.  
  6.     /** Called when the activity is first created. */
  7.  
  8.         TabHost mTabHost;
  9.  
  10.     @Override
  11.  
  12.     public void onCreate(Bundle savedInstanceState) {
  13.  
  14.         super.onCreate(savedInstanceState);
  15.  
  16.         setContentView(R.layout.main);    
  17.  
  18.         mTabHost = getTabHost();        
  19.  
  20.         mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Test1").setContent(R.id.lottopicker));  
  21.  
  22.         mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Test2").setContent(R.id.settings));    
  23.  
  24.         mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Test3",getResources().getDrawable(R.drawable.icon)).setContent(new Intent(this, List1.class)));
  25.  
  26.          }
  27.  
  28.     }
  29.  
  30.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


And the List1.java-file (exactly like the one in the sdk-api-demo, its called controls_2 there):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. ...
  5.  
  6.         public class List1 extends Activity {
  7.  
  8.             /** Called when the activity is first created. */
  9.  
  10.                 @Override
  11.  
  12.             public void onCreate(Bundle savedInstanceState) {
  13.  
  14.                 super.onCreate(savedInstanceState);
  15.  
  16.                 setContentView(R.layout.expla);
  17.  
  18.                
  19.  
  20.                 Spinner s1 = (Spinner) findViewById(R.id.spinner1);
  21.  
  22.                 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  23.  
  24.                         android.R.layout.simple_spinner_item, mStrings);
  25.  
  26.                 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  27.  
  28.                 s1.setAdapter(adapter);
  29.  
  30. }
  31.  
  32.                 private static final String[] mStrings = {
  33.  
  34.                     "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"
  35.  
  36.             };
  37.  
  38.         }
  39.  
  40.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Thanks in advance,

Harry
Last edited by harryh99 on Wed Jan 20, 2010 11:23 am, edited 1 time in total.
harryh99
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Jan 10, 2010 12:33 pm

Top

Tabhost.addtab with intent crashes (solved)

Postby harryh99 » Wed Jan 20, 2010 11:23 am

Hi,

i solved my problem. I had to add the List1-Activity to my manifest inside the application-tab:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  <activity android:name="List1"></activity>
  3.  
  4.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Thanks,

Harry
harryh99
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Jan 10, 2010 12:33 pm

Postby Draffodx » Wed Jan 20, 2010 4:45 pm

Just a quick thanks for posting your solution, too many people go off and solve there problems withou coming back and explaining how they did for anyone that searches the same problem,

So thanks :D
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests