2014-04-11 21 views
0

我有Android應用程序在那裏我得到以前的活動字符串,並將其轉移到下一個活動。 工作正常,當我做一個標籤。但是當我的第二個選項卡中指定它的應用程序崩潰,安卓:錯誤越來越TabView的應用程序崩潰

錯誤日誌貓,你必須指定一個方法來創建選項卡指示器。

代碼解決

package com.example.pms; 

import android.app.TabActivity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.os.Bundle; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.TabHost; 
import android.widget.TabHost.OnTabChangeListener; 
import android.widget.TextView; 
import android.widget.TabHost.TabSpec; 






public class TabControl extends TabActivity 
{ 
    public static TabControl mTabControl; 
    public static TextView textView; 
    public static TabHost tabHost ; 
    final Context context = this; 
    //public static String strEmployeeID = ""; 
    @SuppressWarnings("deprecation") 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     Resources resources = getResources(); 
     TabHost tabHost = getTabHost(); 




      Bundle extras = getIntent().getExtras(); 
      String strEmployeeID=""; 
     TabSpec photospec = tabHost.newTabSpec("Hourly entry"); 
      // setting Title and Icon for the Tab 
      photospec.setIndicator("Hourly Entry"); 

       if (extras != null) 
       { 

        String value = extras.getString("new_variable_name"); 
//    Toast.makeText(getBaseContext(), value, Toast.LENGTH_LONG).show(); 
        strEmployeeID = value; 
       } 


      Intent photosIntent = new Intent(getApplicationContext(), HourlyEntry.class); 
      photosIntent.putExtra("new_variable_name",strEmployeeID); 
      photospec.setContent(photosIntent); 



      TabSpec photospec1 = tabHost.newTabSpec("Leave app"); 
       // setting Title and Icon for the Tab 
       photospec1.setIndicator("Leave App"); 

        if (extras != null) 
        { 

         String value = extras.getString("new_variable_name"); 
//     Toast.makeText(getBaseContext(), value, Toast.LENGTH_LONG).show(); 
         strEmployeeID = value; 
        } 


       Intent photosIntent1 = new Intent(getApplicationContext(), LeaveApp.class); 
       photosIntent1.putExtra("new_variable_name",strEmployeeID); 
       photospec1.setContent(photosIntent1); 


     tabHost.addTab(photospec); 
     tabHost.addTab(photospec1); 



     tabHost.setCurrentTab(0); 

    } 


} 
+0

你加LeaveApp,HourlyEntry到Manifiest? –

+0

然後發佈您的logcat。 –

+0

是的...我只是發佈我的日誌貓 –

回答

2

更改此

TabSpec photospec1 = tabHost.newTabSpec("Photos"); 
     // setting Title and Icon for the Tab 
    photospec.setIndicator("", getResources().getDrawable(R.drawable.tab_home)); 

隨着

 TabSpec photospec1 = tabHost.newTabSpec("Photos2"); 
      // setting Title and Icon for the Tab 
    photospec1.setIndicator("", getResources().getDrawable(R.drawable.tab_home)); 
     if (extras != null) 

       { 
        String value = extras.getString("new_variable_name"); 
        strEmployeeID = value; 
       } 

     Intent photosIntent1 = new Intent(getApplicationContext(), LeaveApp.class); 
     photosIntent1.putExtra("new_variable_name",strEmployeeID); 
     photospec1.setContent(photosIntent1); 

而且您的問題就在這裏,你永遠不會設置Tab Indicator到第二個選項卡正確李柯下面

photospec1.setIndicator("", getResources().getDrawable(R.drawable.tab_home)); 

,也是你的問題就在這裏,你設置錯誤set Content Intent到第二個選項卡正確象下面這樣:

Intent photosIntent1 = new Intent(getApplicationContext(), LeaveApp.class); 
    photosIntent1.putExtra("new_variable_name",strEmployeeID); 
    photospec1.setContent(photosIntent1); 
相關問題