Webからアプリケーションのドロワーメニューに写真をロードするのにピカソを使用しています。view.findViewByIdはnullを返します。これはPicassoを使って "Target is null"エラーになります。
</FrameLayout>`<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:clickable="true">
<LinearLayout
android:id="@+id/vGlobalMenuHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivMenuUserProfilePhoto"
android:layout_width="@dimen/global_menu_avatar_size"
android:layout_height="@dimen/global_menu_avatar_size"
android:layout_margin="12dp" />
</LinearLayout>
ここ
は私のJavaファイルです: しかし、今、私はここに一日 のために捕獲されたてきた問題を得たが、私のxmlです今とき
public class MyMenuFragment extends MenuFragment {
private ImageView ivMenuUserProfilePhoto;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_menu, container,
false);
ivMenuUserProfilePhoto = (ImageView)view.findViewById(R.id.ivMenuUserProfilePhoto);
setupHeader();
return setupReveal(view) ;
}
private void setupHeader() {
int avatarSize = getResources().getDimensionPixelSize(R.dimen.global_menu_avatar_size);
String profilePhoto = getResources().getString(R.string.user_profile_photo);
Picasso.with(getActivity())
.load(profilePhoto)
.placeholder(R.drawable.img_circle_placeholder)
.resize(avatarSize, avatarSize)
.centerCrop()
.transform(new CircleTransformation())
.into(ivMenuUserProfilePhoto);
}
Iこのプロジェクトを実行すると、コンソールは「原因:java.lang.IllegalArgumentException:ターゲットをnullにすることはできません」というエラーを報告します。
デバッグした結果、ivMenuUserProfilePhotoは実際にはnullですが、なぜわかりませんか?findviewByIdは機能しません。
ありがとうございました!しかし、それはコピー貼り間違いです、ごめんなさい – Zafir
母、心配しないで、誰もがそれをxD – Patrick