我的Android应用程序在12小时后重新启动时崩溃了'空闲时间。
我一直在尝试在任何地方添加空构造函数(因为崩溃日志告诉我这样做),但仍然失败。
以下是崩溃日志:
E/AndroidRuntime(22225): FATAL EXCEPTION: main
E/AndroidRuntime(22225): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abcde.com/com.abcde.com.HomeActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.abcde.com.BaseSlideActivity$12: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime(22225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2080)
E/AndroidRuntime(22225): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
E/AndroidRuntime(22225): at android.app.ActivityThread.access$600(ActivityThread.java:136)
E/AndroidRuntime(22225): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
E/AndroidRuntime(22225): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(22225): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(22225): at android.app.ActivityThread.main(ActivityThread.java:4881)
E/AndroidRuntime(22225): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(22225): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(22225): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:804)
E/AndroidRuntime(22225): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:571)
E/AndroidRuntime(22225): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(22225): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.abcde.com.BaseSlideActivity$12: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime(22225): at android.support.v4.app.Fragment.instantiate(Fragment.java:413)
E/AndroidRuntime(22225): at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
E/AndroidRuntime(22225): at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1801)
E/AndroidRuntime(22225): at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
E/AndroidRuntime(22225): at com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity.onCreate(SlidingFragmentActivity.java:23)
E/AndroidRuntime(22225): at com.abcde.com.BaseSlideActivity.onCreate(BaseSlideActivity.java:61)
E/AndroidRuntime(22225): at com.abcde.com.HomeActivity.onCreate(HomeActivity.java:112)
E/AndroidRuntime(22225): at android.app.Activity.performCreate(Activity.java:5084)
E/AndroidRuntime(22225): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime(22225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044)
E/AndroidRuntime(22225): ... 11 more
E/AndroidRuntime(22225): Caused by: java.lang.InstantiationException: can't instantiate class com.abcde.com.BaseSlideActivity$12; no empty constructor
E/AndroidRuntime(22225): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(22225): at java.lang.Class.newInstance(Class.java:1319)
E/AndroidRuntime(22225): at android.support.v4.app.Fragment.instantiate(Fragment.java:402)
E/AndroidRuntime(22225): ... 20 more
HomeActivity.java
public class HomeActivity extends BaseSlideActivity implements
TutorialFragmentListener {
private String TAG = this.getClass().getSimpleName();
public String mLastSelectedMenu = "";
// private Fragment mLastContentFragment = null;
private boolean isRestart;
private MenuData lastMenuData;
private List<String> fragmentNameHistory = new ArrayList<String>();
public int currentOrientation;
public float currentFontScale;
public static boolean isOrientationChanged = false;
public boolean isLanguageChanged = false;
public boolean isJumpToMycoupons = false;
public boolean isLogin;
public BocApplication application;
public FrameLayout layout_post;
public FrameLayout layout_pre;
public RelativeLayout layout_cover;
public static AQuery globalAQuery;
public static boolean isMainPageClicked;
public MenuFragmentAutoHighlighter menuFragmentAutoHighlighter;
boolean testPush = false;
public HomeActivity() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
mTitleRes = R.string.home;
super.onCreate(savedInstanceState);
try {
MapsInitializer.initialize(getApplicationContext());
} catch (GooglePlayServicesNotAvailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
menuFragmentAutoHighlighter = new MenuFragmentAutoHighlighter(this);
Utils.mContext = getApplicationContext();
Utils.getDisplayImageOptions(this);
application = (BocApplication) getApplication();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
this).writeDebugLogs().build();
ImageLoader.getInstance().init(config);
currentOrientation = getResources().getConfiguration().orientation;
currentFontScale = getResources().getConfiguration().fontScale;
// mLastContentFragment = null;
setContentView(R.layout.activity_home);
globalAQuery = new AQuery(this);
layout_post = (FrameLayout) findViewById(R.id.postlogon_content_frame);
layout_pre = (FrameLayout) findViewById(R.id.content_frame);
// layout_cover = (RelativeLayout)findViewById(R.id.layout_cover);
// Loading Mask
makeLoadingMask();
prepareOverlayWebView();
// LoadingMask.getCurrentInstance().flushLoadingView().refresh();
// VAN: PUSH CHECK SHOULD LAUNCH CERTAIN PAGE HERE!
if (!checkPushNotificationLaunchPage())
{
Fragment dashboardFragment = ContentFragmentHelper.getContentFragment(
this, genHomeMenuData());
changeFragment(dashboardFragment, null);
}
initDb();
findViewById(R.id.view_overlay).setOnTouchListener(
new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
SlidingMenu sm = getSlidingMenu();
sm.setOnClosedListener(menuClosedListener);
}
BaseSlideActivity.java
public class BaseSlideActivity extends SlidingFragmentActivity {
protected int mTitleRes;
private View mFrameTitleButton;
private View mFrameEditButton;
private View mLeftMenuButton;
private View mBackButton;
private View mRightMenuButton;
protected View mLoginButton;
protected View mRightDivider;
protected View mDoneButton;
protected TextView mResetButton;
protected TextView mCancelButton;
protected TextView mLoginButtonTitle;
protected TextView mDoneButtonTitle;
public MenuFragment mLeftMenuFragment;
protected RightMenuFragment mRightMenuFragment;
protected ActionBarListener mActionBarDoneListener;
protected ActionBarListener mActionBarResetListener;
protected ActionBarListener mActionBarCancelListener;
public BaseSlideActivity() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// isTablet checking
if (!Utils.isTablet(this)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
initActionBar();
setTitle(mTitleRes);
initSlidingMenu(savedInstanceState);
}
SlidingFragmentActivity.java
public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {
private SlidingActivityHelper mHelper;
public SlidingFragmentActivity() {
}
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHelper = new SlidingActivityHelper(this);
mHelper.onCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#onPostCreate(android.os.Bundle)
*/
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate(savedInstanceState);
}
有人可以给我一些线索吗?
更新2014/10/15 11:00 AM:MenuFragmentAutoHighlighter.java
public class MenuFragmentAutoHighlighter {
public HomeActivity homeActivity;
public MenuFragmentAutoHighlighter(HomeActivity homeActivity)
{
this.homeActivity = homeActivity;
}
public void tryHighlightMenuItemByBaseFragmentClass(Fragment fragment)
{
if (homeActivity == null || homeActivity.mLeftMenuFragment == null)
{
return;
}
homeActivity.mLeftMenuFragment.setSelectedPreMenuItem(
ContentFragmentHelper.MENU_HOME,
null);
}
}
答案 0 :(得分:0)
您发布的BaseSlideActivity的构造函数(以及所有其他构造函数)不应为空,因为此类扩展了SlidingFragmentActivity。 您应该在其中添加一个调用(以及在扩展其他类的所有其他类的构造函数中)调用:
super.CLASS_NAME(); //a call to the super class's empty constructor