以前は、viewPager の一部としてフラグメントで複製しようとしているアクティビティ レイアウトがありました。競合が発生した場合に備えて、古い XML ファイルをコピーし、すべての ID を変更しました。このフラグメントの新しい XML レイアウトと作成された新しい ID を参照しています。しかし、実行するとこの nullpointerexception が発生します。
ここにlogcatファイルがあります http://i48.tinypic.com/14ekq6s.png
エラーが発生する Java ファイルの部分を次に示します。
@Override
public RelativeLayout onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
return null;
}
inflater.inflate(R.layout.one, null);
ViewPager viewFinder = (ViewPager) getView();
//setContentView(R.layout.one);
title = (TextView) viewFinder.findViewById(R.id.frag_AA); //ERROR xml id file probz
そして、これがレイアウトファイルです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/frag_AA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="I Am Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>