I'm using picasso to load pics from web to my app's drawer menu. But now I got a problem which I've been trapped in for whole day here is my xml:
</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>
Here is my Java file:
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);
}
Now when I run this project , the console reports the error" Caused by: java.lang.IllegalArgumentException: Target must not be null."
I debugged, found that the ivMenuUserProfilePhoto indeed is null, but I don't know why.how come that the findviewById doesn't work?