目前我正在实现一个片段来显示图像,但我尝试使用https://github.com/chrisbanes/PhotoView并且它崩溃了
这是代码:
public class StorelayoutFragment extends Fragment {
ImageView mImageView;
PhotoViewAttacher mAttacher;
public StorelayoutFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.fragment_store_layout, container, false);
// Any implementation of ImageView can be used!
mImageView = (ImageView) view.findViewById(R.id.imageView);
// Set the Drawable displayed
Drawable bitmap = getResources().getDrawable(R.drawable.small_layout);
mImageView.setImageDrawable(bitmap);
// Attach a PhotoViewAttacher, which takes care of all of the zooming functionality.
// (not needed unless you are going to change the drawable later)
mAttacher = new PhotoViewAttacher(mImageView);
return view;
}}
我得到的错误是:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sp.ez_mart_z, PID: 18272
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
at com.sp.ez_mart_z.StorelayoutFragment.onCreateView(StorelayoutFragment.java:42)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
有什么建议么?