Android java.lang.NoSuchMethodError: , happen on Intel x86 only (or lower Android version 4.4, 5.0)
Android java.lang.NoSuchMethodError: , happen on Intel x86 only (or lower Android version 4.4, 5.0)
我的 android 应用程序抛出 NoSuchMethodError
并且它只发生在英特尔 x86 平台上。您可以在第 744 行看到代码并在下面登录。
我猜是因为在x86上的兼容性大约setSpan
或getEditableText
,但搜索没有找到相关提示。有没有人有类似的经历?
提前感谢您的任何建议!
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.access0(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() 的替代方法?
欢迎任何建议!
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.
从下面的post来看,应该是getColor()方法被弃用导致的。
我作为建议修改为 ContextCompat.getColor(context, R.color.your_color);并且还没有发生这个 NoSuchMethodError。
我的 android 应用程序抛出 NoSuchMethodError
并且它只发生在英特尔 x86 平台上。您可以在第 744 行看到代码并在下面登录。
我猜是因为在x86上的兼容性大约setSpan
或getEditableText
,但搜索没有找到相关提示。有没有人有类似的经历?
提前感谢您的任何建议!
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.access0(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() 的替代方法? 欢迎任何建议!
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.
从下面的post来看,应该是getColor()方法被弃用导致的。 我作为建议修改为 ContextCompat.getColor(context, R.color.your_color);并且还没有发生这个 NoSuchMethodError。