我有一个导航抽屉,里面有多个选项,如展览,艺术家和画廊。当我点击我的展览中的内容视图中的项目时,它可以正常工作。在预览单个片段活动中的项目后,如果我尝试导航到其他导航抽屉项目(例如艺术家或图库),则整个应用程序崩溃。任何人都可以帮忙吗?
代码 ..
private class LoadViewTask extends AsyncTask<Void, Integer, Void> {
Activity mContex;
GridView listView;
public LoadViewTask(Activity mContext, GridView grid_view) {
.......
}
@Override
protected void onPreExecute() {
....
}
@Override
protected Void doInBackground(Void... params) {
...........
}
@Override
protected void onPostExecute(Void result) {
progressDialog.dismiss();
if(getActivity()!=null){
loadListing();
}
}
private void loadListing() {
ChannelAppProductsArrayAdapter adapter = new ChannelAppProductsArrayAdapter(
mContex, R.layout.itemlisting, productList, imageLoader);
listView.setAdapter(adapter);
//EDITED VERSION TO INITIATE SLIDER DRAWER
mDrawer = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout);
//prevent user from manually opening the drawer
mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
//Allow ScrollView at the preview-layout
ScrollView SV= (ScrollView) getActivity().findViewById(R.id.scrollView_Preview_Layout);
SV.scrollTo(0, 0);
SV.fullScroll(ScrollView.FOCUS_UP);
//END OF EDITED VERSION TO INITIATE SLIDER DRAWER
//listView.setOnClickListener()
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/*String text = "Item click... should be implemented @ position: "
+ position;
Toast.makeText(mContex, text, Toast.LENGTH_LONG).show();*/
Product product = productList.get(position);
String productID = product.getId();
String productDesc = product.getName();
TextView ProductSummary;
String productName=product.getDescription();
TextView ProductName;
ImageView productImage;
imageLargename=productList.get(position).getLarge_image();
//EDITED VERSION TO SHOW RIGHT DRAWER-18/11/2014
mDrawerToggle = new CustomActionBarDrawerToggle(getActivity(), mDrawer);
mDrawer.openDrawer(GravityCompat.END);
mDrawer.setDrawerListener(mDrawerToggle);
getActivity().getActionBar().setHomeButtonEnabled(true); // Prevents user from opening the drawer using the app icon
Log.i("View onItemClick: ArtistProductDetailsFragment", "toggleRightDrawer()"+ productDesc);
//END OF EDITED VERSION TO SHOW RIGHT DRAWER-18/11/2014
//EDITED VERSION TO DISPLAY VIEW FOR SELECTED FRAGMENT ITEM-19/11/2014
View RDrawerView = mDrawer.findViewById(R.id.preview_layout);
//To set TextView of Product Name
ProductSummary = (TextView) RDrawerView.findViewById(R.id.productsummary);
ProductSummary.setText(productDesc);
//To set TextView of product description
ProductName= (TextView) RDrawerView.findViewById(R.id.productdesc);
ProductName.setText(productName);
//To get product Image from array
productImage =(ImageView) RDrawerView.findViewById(R.id.productimage);
String imgFilePath = url + imageLargename;
imageLoader.displayImage(imgFilePath, productImage, options);
productImage.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(mContex,
"Pinch & Zoom To See Large Photo.",
Toast.LENGTH_SHORT).show();
String imgFilePath = url + imageLargename;
Intent intent = new Intent(
mContex.getApplicationContext(),
FullScreenViewActivity.class);
intent.putExtra("path", imgFilePath);
startActivity(intent);
}
});
//END OF EDITED VERSION TO DISPLAY VIEW FOR SELECTED FRAGMENT ITEM-19/11/2014
}
});
}
//EDITED VERSION FOR CUSTOMACTIONBARDRAWERTOGGLE
private class CustomActionBarDrawerToggle extends ActionBarDrawerToggle {
public CustomActionBarDrawerToggle(Activity mActivity,
DrawerLayout mDrawerLayout) {
super(mActivity, mDrawerLayout, R.drawable.ic_drawer,
R.string.ns_menu_open, R.string.ns_menu_close);
}
@Override
public void onDrawerClosed(View view) {
getActivity().getActionBar().setTitle(getActivity().getString(R.string.ns_menu_close));
getActivity().invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
@Override
public void onDrawerOpened(View drawerView) {
getActivity().getActionBar().setTitle(getActivity().getString(R.string.ns_menu_open));
getActivity().invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
}
//END OF EDITED VERSION FOR CUSTOMACTIONBARDRAWERTOGGLE
}
错误记录 ..
11-26 10:47:50.719: E/AndroidRuntime(19168): FATAL EXCEPTION: main
11-26 10:47:50.719: E/AndroidRuntime(19168): java.lang.NullPointerException
11-26 10:47:50.719: E/AndroidRuntime(19168): at com.dapoaugury.channelappdemo.fragment.ChannelAppProductFragment$LoadViewTask$CustomActionBarDrawerToggle.onDrawerClosed(ChannelAppProductFragment.java:332)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.support.v4.widget.DrawerLayout.dispatchOnDrawerClosed(DrawerLayout.java:477)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.support.v4.widget.DrawerLayout.updateDrawerState(DrawerLayout.java:457)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.support.v4.widget.DrawerLayout$ViewDragCallback.onViewDragStateChanged(DrawerLayout.java:1355)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.support.v4.widget.ViewDragHelper.setDragState(ViewDragHelper.java:866)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.support.v4.widget.ViewDragHelper$2.run(ViewDragHelper.java:335)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.os.Handler.handleCallback(Handler.java:725)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.os.Looper.loop(Looper.java:137)
11-26 10:47:50.719: E/AndroidRuntime(19168): at android.app.ActivityThread.main(ActivityThread.java:5039)
11-26 10:47:50.719: E/AndroidRuntime(19168): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 10:47:50.719: E/AndroidRuntime(19168): at java.lang.reflect.Method.invoke(Method.java:511)
11-26 10:47:50.719: E/AndroidRuntime(19168): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-26 10:47:50.719: E/AndroidRuntime(19168): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-26 10:47:50.719: E/AndroidRuntime(19168): at dalvik.system.NativeStart.main(Native Method)
编辑1:
我已经解决了自己的问题。感谢。
那就是完全删除private class CustomActionBarDrawerToggle extends ActionBarDrawerToggle
的整个方法。我已经意识到它不适用于第二个抽屉,因为它没有在操作栏上调用任何滑动抽屉功能。
答案 0 :(得分:0)
那就是完全删除私有类CustomActionBarDrawerToggle extends ActionBarDrawerToggle