2017-06-01 27 views
0

我的Android應用程序拋出NoSuchMethodError,它只發生在intel x86平臺上。您可以在744行上看到代碼並記錄在下面。Android java.lang.NoSuchMethodError:,僅在Intel x86上發生(或更低的Android版本4.4,5.0)

我想這是因爲x86上的兼容性約setSpangetEditableText,但搜索沒有找到相關的提示。有沒有人有類似的經歷?

在此先感謝您的任何建議!

textView2.getEditableText().setSpan(new ForegroundColorSpan(
getColor(R.color.colorMiddleBlue)) 
, nowLength 
, endSelection 
, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

java.lang.NoSuchMethodError: 
    at com.SouthernPacificOceanFisher.speaking.MainActivity.showSentenceSpoken(MainActivity.java:744) 
    at com.SouthernPacificOceanFisher.speaking.MainActivity.processOneSentence(MainActivity.java:757) 
    at com.SouthernPacificOceanFisher.speaking.MainActivity.initSentences(MainActivity.java:793) 
    at com.SouthernPacificOceanFisher.speaking.MainActivity.initDirFile_Text(MainActivity.java:825) 
    at com.SouthernPacificOceanFisher.speaking.MainActivity.onCreate(MainActivity.java:340) 
    at android.app.Activity.performCreate(Activity.java:5541) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464) 
    at android.app.ActivityThread.access$900(ActivityThread.java:172) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:146) 
    at android.app.ActivityThread.main(ActivityThread.java:5653) 
    at java.lang.reflect.Method.invokeNative(Native Method:0) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
    at dalvik.system.NativeStart.main(Native Method:0) 

通過@ Micho的建議下,我拆語句下面,

Editable editable = textView2.getEditableText(); 
    int color1 = getColor(R.color.colorMiddleBlue); 
    ForegroundColorSpan FcolorSpan = new ForegroundColorSpan(color1); 
    editable.setSpan(FcolorSpan, nowLength, endSelection,  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

,發現有一個大約的getColor警告()。我不確定是否它是java.lang.NoSuchMethodError的原因(或者崩潰報告只發生在較低的Android版本4.4,5.0上。 試圖修復此警告。是否有替代getColor()? Any建議是歡迎

Call requires API level 23 (current min is 15): 
android.content.Context#getColor less... (Ctrl+F1) 
This check scans through all the Android API calls in the application and 
warns about any calls that are not available on all versions targeted by 
this application (according to its minimum SDK attribute in the manifest). 
If you really want to use this API and don't need to support older 
devices just set the minSdkVersion in your build.gradle or 
AndroidManifest.xml files. 
If your code is deliberately accessing newer APIs, and you have ensured 
(e.g. with conditional execution) that this code will only ever be called 
on a supported platform, then you can annotate your class or method with 
the @TargetApi annotation specifying the local minimum SDK to apply, such 
as @TargetApi(11), such that this check considers 11 rather than your 
manifest file's minimum SDK as the required API level. 
If you are deliberately setting android: attributes in style definitions, 
make sure you place this in a values-vNN folder in order to avoid running 
into runtime conflicts on certain devices where manufacturers have added 
custom attributes whose ids conflict with the new ones on later 
platforms. Similarly, you can use tools:targetApi="11" in an XML file to 
indicate that the element will only be inflated in an adequate context. 
+0

應該很容易找出它是哪種方法。將該語句拆分爲多個包含至多一個方法的語句,然後再次運行代碼。 – Michael

回答

相關問題