UnsupportedOperationException - 随机错误 - OnBackPressed

时间:2014-12-16 12:17:51

标签: android mupdf onbackpressed unsupportedoperation

在运行我的Android代码时,我得到了不受支持的操作异常,RANDOMLY。抛出此异常后,我的应用程序崩溃了。如何处理相同的,以及抛出此EXCEPTION的基本原因是什么。

示例1:

@Override
public View getSelectedView() {
    throw new UnsupportedOperationException("Not supported");
}

示例2:

@Override
public void onBackPressed() {

    if(slideContent.getVisibility()==View.VISIBLE)
        slideContent.setVisibility(View.GONE);
    if(searchAutoCompleteText.getText().toString().length()>0)
        searchAutoCompleteText.setText("");
    else{
        super.onBackPressed();
    }
}

logcat的:

java.lang.UnsupportedOperationException
com.artifex.mupdfdemo.ReaderView.getSelectedView(ReaderView.java:751)
android.widget.AdapterView.onInitializeAccessibilityEvent(AdapterView.java:1014)
android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5150)
android.view.View.sendAccessibilityEventUnchecked(View.java:5135)
android.view.ViewRootImpl$SendWindowContentChangedAccessibilityEvent.run(ViewRootImpl.java:7463)
android.os.Handler.handleCallback(Handler.java:733)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:157)
android.app.ActivityThread.main(ActivityThread.java:5335)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
dalvik.system.NativeStart.main(Native Method)

上面写的是我收到UNSUPPORTEDOperationException和Application Crashed的几种情况。如果有人知道,请告诉我ROOT CAUSE。

1 个答案:

答案 0 :(得分:6)

返回null而不是UnsupportedOperationException

@Override
public View getSelectedView() {
    //throw new UnsupportedOperationException(getContext().getString(R.string.not_supported));
        return null;
}

检查this