2013-07-18 1 views
1

사진과 xml을 이미 설정했는지 확인합니다. 나는 안드로이드 에뮬레이터에서 내 애플 리케이션을 실행, 그냥 팝업 창이 실행을 중지 한 것을 보여 주었다. 그러나 res.getDrawable(R.drawable.tab_icon1), res.getDrawable(R.drawable.tab_icon2)res.‌​getDrawable(R.drawable.tab_icon3)을 포함한 아이콘 부분을 삭제 한 후 앱이 정상적으로 작동합니다.은 tabspec에 아이콘을 설정할 수 없습니다.

public class ActionBar extends Activity implements OnClickListener { 

TabHost th; 
TextView showResult; 
long start, stop; 
Resources res; 

protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_action_bar); 
    th = (TabHost) findViewById(R.id.tabhost); 
    th.setup(); 
    Button newTab = (Button) findViewById(R.id.bAddTab); 
    Button start = (Button) findViewById(R.id.bStart); 
    Button stop = (Button) findViewById(R.id.bStop); 
    showResult = (TextView) findViewById(R.id.textView1); 
    newTab.setOnClickListener(this); 
    start.setOnClickListener(this); 
    stop.setOnClickListener(this); 
    TabSpec specs = th.newTabSpec("tab1"); 
    specs.setContent(R.id.tab1); 
    specs.setIndicator("Stop Watch", res.getDrawable(R.drawable.tab_icon1)); 
    th.addTab(specs); 
    specs = th.newTabSpec("tab2"); 
    specs.setContent(R.id.tab2); 
    specs.setIndicator("Add Tab", res.getDrawable(R.drawable.tab_icon2)); 
    th.addTab(specs); 
    specs = th.newTabSpec("tab3"); 
    specs.setContent(R.id.tab3); 
    specs.setIndicator("Blank", res.getDrawable(R.drawable.tab_icon3)); 
    res = getResources(); 
    th.addTab(specs); 
} 
+0

@SimonH 앱을 실행할 때 앱이 중지되었지만 res.getDrawable (R.drawable.tab_icon1), res.getDrawable (R.drawable.tab_icon2), res.getDrawable (R.drawable. tab_icon3), 애플 리케이션이 잘 작동 –

+0

나는 안드로이드 에뮬레이터에서 실행, 그냥 팝업 창이 실행을 멈춘 앱을 보여줬다 –

+0

정말 고마워요 !! 한 번 더 질문, 아이콘 내 버전에 표시 2.2하지만 에뮬레이터 버전 4.2에서는 텍스트 만 포함 된 이유는 무엇입니까? –

답변

0

난 당신이 모두 세 곳에서 res 변수를 사용하기 전에 res = getResources();을 정의해야한다는 것입니다 볼 수있는 한 간단 것. 지금은 그것을 정의하기 전에 사용하고있어 예외를 던질 수도 있습니다. 다음과 같이하십시오 :

//.... 
res = getResources(); 
specs.setContent(R.id.tab1); 
specs.setIndicator("Stop Watch", res.getDrawable(R.drawable.tab_icon1)); 
th.addTab(specs); 
specs = th.newTabSpec("tab2"); 
specs.setContent(R.id.tab2); 
specs.setIndicator("Add Tab", res.getDrawable(R.drawable.tab_icon2)); 
th.addTab(specs); 
specs = th.newTabSpec("tab3"); 
specs.setContent(R.id.tab3); 
specs.setIndicator("Blank", res.getDrawable(R.drawable.tab_icon3)); 
//.... 

추가 도움이 필요하면 LogCat 정보를 게시하십시오. 희망이 도움이됩니다.

+0

@Xiu Tiger Yi : 4.2 안드로이드 에뮬레이터에서 어떤 오류가 있습니까? LogCat을 사용할 수 있습니까? –