이것은 지난 날 저를 괴롭혔습니다. 그래서 계속 mTabHost, onCreate()의 변수에 대한 null 포인터 참조를 얻습니다. 내 주요 활동에서TabHost (Android)에 대한 참조에서 널 포인터 가져 오기
: 여기에 관련 코드의
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
instance = this;
setContentView(R.layout.second_activity);
// Initializing ViewPager and TabHost objects:
mViewPager = new ViewPager(this);
mViewPager.setId(R.id.viewpager);
setContentView(mViewPager);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this,getSupportFragmentManager());
}
그리고 여기 second_activity.xml입니다 :
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom">
<fragment android:name="com.yolostudios.dots.main.login.LoginFragment"
android:id="@+id/login_fragment"
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:visibility="gone"/>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="8" >
<include
android:layout_width="fill_parent"
android:layout_height="60dip"
android:visibility="invisible"
android:layout_gravity="bottom"
android:focusable="true"
layout="@layout/createspotbutton" />
</android.support.v4.view.ViewPager>
<!-- Loading header of this UI which is coded separately -->
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="50dp" >
<include
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp"
layout="@layout/toolbar" />
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
내가 mTabHost.setup (이 프로그램을 실행할 때 실제 예외가 발생, getSupportFragmentManager()) mTabHost는 null입니다.
뭔가 이상한 점은 Support4Demos에서 제공되는 샘플 FragmentTabs도 나를 위해 작동하지 않는다는 것입니다. 나는 이것이 내 안드로이드 지원 v4.jar 또는 내 환경에 문제가 있음을 알려주고 있지만 항아리를 다시 다운로드하고 다시 컴파일하려고했지만 여전히 아무것도 작동하지 않는다는 것을 확신합니다. 컴파일에도 불구하고 내 프로젝트와 런타임시 샘플 프로젝트가 실패합니다. 다른 가능한 환경 문제에 관해서, 나는 그들이 무엇이 될 수 있는지 잘 모르겠습니다.
의견을 보내 주시면 감사하겠습니다.
감사합니다. Andrew.
'android.R.id.tabhost'에서'android.'를 제거하십시오, 나는 Eclipse가 그것을 원한다는 것을 알고 있습니다. – Vikram
Tarsem의 대답에 대한 제 응답을 참조하십시오 –
클래스가'FragmentActivity'를 확장합니까? – Vikram