2010-02-17 8 views
1

두 개의 탭으로 탭 위젯을 만들어 두 개의 다른 액티비티를 열고 이것을 달성하기 위해 레이아웃을 작성했지만 NullPointerException이되었습니다.TabWidget NullpointerException?

내 실수는 어디에서 왔습니까? TabWidget을 확장하는 자바 클래스에서

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

내가 가지고있는 onCreate 방법에 다음 코드 :

setContentView(R.layout.more); 

TabHost mTabHost = (TabHost) this.findViewById(R.id.tabhost); 
mTabHost.setup(); 

Intent intent; 

intent = new Intent().setClass(this, Settings.class); 
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(
         "Calculator", 
         getResources().getDrawable(R.drawable.tab01)).setContent(intent)); 

intent = new Intent().setClass(this, Post.class);     
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator(
         "YouTube", 
         getResources().getDrawable(R.drawable.tab02)).setContent(intent)); 
+1

Eclipse에서 'adb logcat', DDMS 또는 DDMS 퍼스펙티브를 사용하여 스택 추적을 검사하면 문제가있는 위치를 알 수 있습니다. – CommonsWare

+0

02-18 11 : 08 : 01.197 : INFO/ActivityManager (52) : 활동 시작 : 의도 {cmp = com.example.FindItear/.more} 02-18 11 : 08 : 11.224 : WARN/ActivityManager (52) : 시작 시간 제한이 만료되어 잠자기 잠금을 포기했습니다. 02-18 11 : 08 : 11.368 : WARN/ActivityManager (52) : HistoryRecord {43dba948 com.example.FindItNear /. More}의 활동 유휴 시간 초과 – UMAR

+0

게시물에 대한 편집 내용으로 의견을 추가하십시오 (서식을 지정할 수 있도록). 그리고 더 쉽게 읽을 수) – KevinDTimm

답변

-1

당신이 TabActivity를 사용하여 탭 클래스를 확장하는 경우 그것은 0,123해야

입니다

"@android : id/tabhost"와 같은 탭 관련 컨트롤의 ID를 사용하는 경우

"@ + id/tabhost"가 잘못 사용되었지만 Activity 클래스를 통해 확장 한 경우에는 괜찮습니다.

내가 오지 않을 레이아웃에 직면 한 문제는 상기

...

탭 가이드는 비트는 다음의 예를 이용하여 해결할 수있는 버그가 하였다. Example

+0

그래서, 너는 그것을 고정 시켰는가 아닌가? – KevinDTimm

+0

예 고정되었습니다 .. – UMAR

0

별로 정보를 원하시면 여기 계속하지만, 내 질문을 확인 (그리고 답변을의)하기위한 잠재적 인 솔루션은
Issues with Android TabHost Example

+0

나는 이미 이러한 문제를 해결했습니다 ..하지만 문제는 내 레이아웃 파일에 있습니다 .. 난 그냥 안드로이드 tabactivity 예제에서 언급 한 레이아웃의 코드를 복사 ... 아직 희망이 .. – UMAR