嗨,伙计们,我从我的开发人员控制台获得了这个堆栈跟踪。好的,我不确定是什么导致了这次崩溃。因为我在测试我的应用程序时从来没有自己遇到过这个错误,只是从谷歌游戏的开发者控制台中得到它。
java.lang.RuntimeException: Unable to start activity ComponentInfo{package.name/package.name.activity.SomeActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment package.name.photopreview.PhotoThumbnailFragmentAdapter$1: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment streetdirectory.mobile.modules.photopreview.PhotoThumbnailFragmentAdapter$1: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1760)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:200)
at streetdirectory.mobile.modules.businessdetail.BusinessDetailActivity.onCreate(BusinessDetailActivity.java:134)
at android.app.Activity.performCreate(Activity.java:5188)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
... 11 more
Caused by: java.lang.InstantiationException: can't instantiate class streetdirectory.mobile.modules.photopreview.PhotoThumbnailFragmentAdapter$1; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.support.v4.app.Fragment.instantiate(Fragment.java:388)
... 18 more
任何人都可以帮我分析这个问题吗?并给我一些有用的建议。感谢和问候 ..
编辑
这是 PhotoPreviewFragmentAdapter 代码。
public class PhotoPreviewFragmentAdapter<T extends ImageListServiceOutput> extends FragmentPagerAdapter {
private ArrayList<T> mData = new ArrayList<T>();
public PhotoPreviewFragmentAdapter(FragmentManager fm) {
super(fm);
}
public void setData(ArrayList<T> data) {
mData = data;
}
@SuppressLint("ValidFragment")
@Override
public Fragment getItem(final int position) {
PhotoPreviewFragment view = new PhotoPreviewFragment() {
@Override
public ImageListServiceOutput getData() {
if (position < mData.size()) {
return mData.get(position);
}
return null;
}
};
return view;
}
@Override
public int getCount() {
// TODO Add Photo Button
//return mData.size()+1;
return mData.size();
}
}
提供一些有关如何重现此崩溃的线索可能会对我有很大帮助。谢谢
编辑
可能问题是(就像Streets Of Boston所说)PhotoTumbnailFragmentAdapter 中的匿名内部类,我在这个方法中使用了它
public Fragment getItem(final int position) {
PhotoThumbnailFragment view = new PhotoThumbnailFragment() {
@Override
public ImageListServiceOutput getData() {
if (position < mData.size()) {
return mData.get(position);
}
return null;
}
public void onPhotoClicked(ImageListServiceOutput data) {
if (mImageClickedListener != null) {
if (data != null) {
Logger.info("Photo Clicked");
mImageClickedListener.onImageClicked(data, position);
} else {
Logger.info("Add Photo Clicked");
mImageClickedListener.onAddImageClicked(position);
}
}
}
};
return view;
}
PhotoThumbnailFragment 是一个独立的类。