在android中的doInBackground方法get exception中添加tabbar

在android中的doInBackground方法get exception中添加tabbar,android,Android,我在doInBackground方法中添加了一个tabbar,在android中得到了一个异常。 有人能告诉我怎么做吗?举个例子。我的代码如下: package com.inquest; import java.util.ArrayList; //import com.inquest.LoginActivity.FetchTask; import android.app.Activity; import android.app.AlertDialog; import android.ap

我在
doInBackground
方法中添加了一个tabbar,在android中得到了一个异常。 有人能告诉我怎么做吗?举个例子。我的代码如下:

package com.inquest;


import java.util.ArrayList;

//import com.inquest.LoginActivity.FetchTask;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;
//TabActivity 

public class HelloTabWidget extends TabActivity 
{
  int width =40;  
  int height =49;
 //private TabHost tabHost;
 TextView txthome;
 TextView txtstock;
 TextView txtcitn;
 TextView txtmyquest;
 Button btn;
 //private ProgressDialog pd = null; 
    private ProgressDialog dlg; 
    private Object data = null; 
    String strusername="";
    String strPassWord="";
    String questGroupId="";
    String userid="";
    String systemuserid="";
    String providerid="";
    private ProgressDialog dialog; 
 public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tab); 


 new TabTask(HelloTabWidget.this).execute(null);

 }







 public class TabTask extends AsyncTask<Void, Void,Void> 
 { 
     private ProgressDialog dlg; 
          private Context ctx; 
     public TabTask(Context context) { 
         ctx = context; 
     } 



     @Override 
     protected void onPreExecute() { 
         super.onPreExecute(); 
         dlg = new ProgressDialog(HelloTabWidget.this); 
         dlg.setMessage("Loading...."); 
         dlg.show();
     } 



  @Override
  protected Void doInBackground(Void... params) {



   try
      {


       Resources res = getResources();
       TabHost.TabSpec spec;
       TabHost tabHost=getTabHost();

       TabWidget tabWidget = tabHost.getTabWidget();
       //TabHost tabHost=(TabHost)this.findViewById(R.)
       //TabHost tabHost =  (TabHost)this.findViewById(R.id.)


       // tabHost.setBackgroundResource(R.color.gray1);
    //tabWidget.setBackgroundResource(R.color.gray1);
       //tabWidget.setBackgroundDrawable(res.getDrawable(R.drawable.quest_tab_bar_icon));
       //tabWidget.setBackgroundColor(R.color.gray1);
       //tabWidget.setBackgroundDrawable(getResources().getDrawable(R.drawable.tabbar));
       Typeface myTypeface = Typeface.createFromAsset(ctx.getAssets(),"verdanab.TTF");
       Typeface myTypeface1 = Typeface.createFromAsset(ctx.getAssets(),"verdana.TTF");
       Intent homeintent;   
       // Create an Intent to launch an Activity for the tab (to be reused) 
       homeintent = new Intent();
        Bundle bundle=getIntent().getExtras();
        String strusername=bundle.get("strUserName").toString();
        String strPassWord=bundle.get("strPassword").toString();
        String questGroupId=bundle.get("questGroupId").toString();
        String userid=bundle.get("userid").toString();
        String systemuserid=bundle.get("systemuserid").toString();
        String providerid=bundle.get("providerid").toString();
         Log.d("home activity username", strusername);
        Log.d("home activity password", strPassWord);
        Log.d("home activityquestGroupId",questGroupId);
           homeintent.setClass(ctx, HomeActivityGroup.class); 
         homeintent.putExtra("strUserName", strusername);
         homeintent.putExtra("strPassWord",strPassWord );
         homeintent.putExtra("questGroupId",questGroupId);
         homeintent.putExtra("userid",userid);
         homeintent.putExtra("systemuserid", systemuserid);
         homeintent.putExtra("checking", "one");

          spec = tabHost.newTabSpec("home").setIndicator("Home",res.getDrawable(R.drawable.home_tab_bar_icon)).setContent(homeintent);
       tabHost.addTab(spec); 

       //homeintent = new Intent().setClass(this,ThemeSearchActivity.class); 
       homeintent = new Intent().setClass(ctx,StockActivity.class);
       homeintent.putExtra("strUserName", strusername);
       homeintent.putExtra("strPassWord",strPassWord );
       homeintent.putExtra("questGroupId",questGroupId);
       homeintent.putExtra("userid",userid);
       homeintent.putExtra("systemuserid", systemuserid);
       homeintent.putExtra("providerid", providerid);  
       spec = tabHost.newTabSpec("stock").setIndicator("Stock",res.getDrawable(R.drawable.stocks_tab_bar_icon)).setContent(homeintent);
       tabHost.addTab(spec);
       homeintent = new Intent().setClass(ctx,ArticleActivity.class); 
          spec = tabHost.newTabSpec("citn").setIndicator("CITN",res.getDrawable(R.drawable.citn_tabbar_icon)).setContent(homeintent);
       tabHost.addTab(spec);
       homeintent = new Intent().setClass(ctx, MyCompaniesActivity.class); 
       spec = tabHost.newTabSpec("myquest").setIndicator("My Quest",res.getDrawable(R.drawable.quest_tab_bar_icon)).setContent(homeintent);
       tabHost.addTab(spec);

       for (int i =0; i < tabWidget.getChildCount(); i++) {
         //tabWidget.getChildAt(i).setBackgroundColor(R.color.black);
          tabWidget.getChildAt(i).getLayoutParams().height = height;
      tabWidget.getChildAt(i).getLayoutParams().width = width;
      RelativeLayout relLayout = (RelativeLayout)tabWidget.getChildAt(i); 
      TextView tv = (TextView)relLayout.getChildAt(1); 
      tv.setTextSize(10.0f);
      //tv.setCompoundDrawablesWithIntrinsicBounds(0, 1, 0, 0);
     tv.setTypeface(myTypeface1);          



            }
      }
             catch (Exception e) {
       // TODO: handle exception
              e.printStackTrace();
      }



         return null;
             //return parservalue;
       }

 }   


}
package.com.inquist;
导入java.util.ArrayList;
//导入com.inquest.LoginActivity.FetchTask;
导入android.app.Activity;
导入android.app.AlertDialog;
导入android.app.ProgressDialog;
导入android.app.TabActivity;
导入android.content.Context;
导入android.content.DialogInterface;
导入android.content.Intent;
导入android.content.res.Resources;
导入android.graphics.Typeface;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.os.Handler;
导入android.os.Message;
导入android.util.Log;
导入android.view.Gravity;
导入android.widget.Button;
导入android.widget.RelativeLayout;
导入android.widget.TabHost;
导入android.widget.TabWidget;
导入android.widget.TextView;
导入android.widget.TabHost.TabSpec;
//TabActivity
公共类HelloTabWidget扩展了TabActivity
{
整数宽度=40;
整数高度=49;
//私有TabHost TabHost;
TextView-txthome;
TextView-txtstock;
文本视图txtcitn;
TextView-txtmyquest;
按钮btn;
//private ProgressDialog pd=null;
私人发展对话;
私有对象数据=null;
字符串strusername=“”;
字符串strPassWord=“”;
字符串questGroupId=“”;
字符串userid=“”;
字符串systemuserid=“”;
字符串providerid=“”;
私人对话;
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
新建TabTask(HelloTabWidget.this).execute(null);
}
公共类TabTask扩展了AsyncTask
{ 
私人发展对话;
私有上下文ctx;
公共选项卡任务(上下文){
ctx=上下文;
} 
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
dlg=新建进度对话框(HelloTabWidget.this);
dlg.setMessage(“加载…”);
dlg.show();
} 
@凌驾
受保护的Void doInBackground(Void…参数){
尝试
{
Resources res=getResources();
TabHost.TabSpec;
TabHost TabHost=getTabHost();
TabWidget TabWidget=tabHost.getTabWidget();
//TabHost TabHost=(TabHost)this.findviewbyd(R.)
//TabHost TabHost=(TabHost)this.findviewbyd(R.id.)
//tabHost.setBackgroundResource(R.color.gray1);
//tabWidget.setBackgroundResource(R.color.gray1);
//tabWidget.setBackgroundDrawable(res.getDrawable(R.drawable.quest_选项卡_栏_图标));
//tabWidget.setBackgroundColor(R.color.gray1);
//tabWidget.setBackgroundDrawable(getResources().getDrawable(R.drawable.tabbar));
Typeface myTypeface=Typeface.createFromAsset(ctx.getAssets(),“verdanab.TTF”);
Typeface MyTypeface 1=Typeface.createFromAsset(ctx.getAssets(),“verdana.TTF”);
意图;意图;
//创建为选项卡启动活动的意图(要重用)
homeintent=新Intent();
Bundle Bundle=getIntent().getExtras();
字符串strusername=bundle.get(“strusername”).toString();
字符串strPassWord=bundle.get(“strPassWord”).toString();
字符串questGroupId=bundle.get(“questGroupId”).toString();
字符串userid=bundle.get(“userid”).toString();
字符串systemuserid=bundle.get(“systemuserid”).toString();
字符串providerid=bundle.get(“providerid”).toString();
Log.d(“家庭活动用户名”,strusername);
Log.d(“家庭活动密码”,strPassWord);
Log.d(“主页活动questGroupId”,questGroupId);
setClass(ctx,HomeActivityGroup.class);
homeintent.putExtra(“strUserName”,strUserName);
homeintent.putExtra(“strPassWord”,strPassWord);
homeintent.putExtra(“questGroupId”,questGroupId);
homeintent.putExtra(“userid”,userid);
homeintent.putExtra(“systemuserid”,systemuserid);
homeintent.putExtra(“检查”、“一”);
spec=tabHost.newTabSpec(“home”).setIndicator(“home”,res.getDrawable(R.drawable.home_选项卡_栏_图标)).setContent(homeintent);
tabHost.addTab(spec);
//homeintent=new Intent().setClass(this,themesearchivity.class);
homeintent=new Intent().setClass(ctx,StockActivity.class);
homeintent.putExtra(“strUserName”,strUserName);
homeintent.putExtra(“strPassWord”,strPassWord);
homeintent.putExtra(“questGroupId”,questGroupId);
homeintent.putExtra(“userid”,userid);
homeintent.putExtra(“systemuserid”,systemuserid);
homeintent.putExtra(“providerid”,providerid);
spec=tabHost.newTabSpec(“stock”).setIndicator(“stock”,res.getDrawable(R.drawable.stocks\u tab\u bar\u图标)).setContent(homeintent);
tabHost.addTab(spec);
homeintent=new Intent().setClass(ctx,ArticleActivity.class);
spec=tabHost.newTabSpec(“citn”).setIndicator(“citn”,res.getDrawable(R.drawable.citn_tabbar_图标)).setContent(homeintent);
tabHost.addTab(spec);
homeintent=new Intent().setClass(ctx,MyCompaniesActivity.class);
spec=tabHost.newTabSpec(“我的任务”).setIndicator(“我的任务”,res.getDrawable(R.drawable.Quest\u tab\u bar\u图标)).setContent(homeintent);
tabHost.addTab(spec);
对于(int i=0;i