-1
フラグメントに描画可能なフォルダからの画像を表示する際に問題があります。 これを表示しようとすると、java.lang.NullPointerException
が表示されます。 ご協力いただければ幸いです。 Androidのフラグメントで画像を表示する
この
は、あなたがXMLで画像にid属性を追加していないので、それは私のコード、public class Fragment4 extends Fragment {
public Fragment4() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate (R.layout.fragment4, container, false);
ImageView image = (ImageView)rootView.findViewById(R.id.image);
image.setImageResource(R.drawable.image123);
return rootView;
}
}
XMLファイル
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
さらに、レイアウトxmlファイルを追加できますか? –
参照されるNullPointerExceptionの行番号は何ですか? (そしてその番号が参照する行はどれですか) –
NullPointerExceptionはこのコード行 "image.setImageResource(R.drawable.image123);"を参照しています。 – Andy