- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用此代码更改我的 NumberPicker
Utils.java:
public static boolean setNumberPickerTextColor(NumberPicker numberPicker, int color) {
boolean result = false;
final int count = numberPicker.getChildCount();
for(int i = 0; i < count; i++){
View child = numberPicker.getChildAt(i);
if(child instanceof EditText){
try{
Field selectorWheelPaintField = numberPicker.getClass()
.getField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint)selectorWheelPaintField.get(numberPicker)).setColor(color);
((EditText)child).setTextColor(color);
numberPicker.invalidate();
result = true;
}
catch(NoSuchFieldException e){
Log.w("NoSuchFieldException: ", e);
}
catch(IllegalAccessException e){
Log.w("IllegalAccessException: ", e);
}
catch(IllegalArgumentException e){
Log.w("IllegalArgumentException:" , e);
}
}
}
return result;
}
我这样调用它:
AmoutProduct.java:
Utils.setNumberPickerTextColor(np0, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
但我收到此错误:
11-07 13:36:46.573 27277-27277/tecniva.mx.fillgas W/NoSuchFieldException:: java.lang.NoSuchFieldException: mSelectorWheelPaint
at java.lang.Class.getField(Class.java:897)
at tecniva.mx.fillgas.util.Utils.setNumberPickerTextColor(Utils.java:467)
at tecniva.mx.fillgas.AmountProduct.enableLitersOption(AmountProduct.java:273)
at tecniva.mx.fillgas.AmountProduct.access$000(AmountProduct.java:37)
at tecniva.mx.fillgas.AmountProduct$2.onClick(AmountProduct.java:102)
at android.view.View.callOnClick(View.java:5718)
at tecniva.mx.fillgas.AmountProduct.didClickLyRbtL(AmountProduct.java:288)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4735)
at android.view.View.performClick(View.java:5697)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
错误发生在行:
.getField("mSelectorWheelPaint");
它说找不到字段 mSelectorWheelPaint,如何解决这个问题?
提前致谢
最佳答案
numberPicker.getClass().getDeclaredField("mSelectorWheelPaint");
使用getDeclaredField
而不是getField
关于java - NoSuchFieldException:NumberPicker Android 中的 mSelectorWheelPaint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40473288/
我们的教授通过 jarpeb sytsem(Java 随机和个性化练习生成器)为我们布置练习。所以变量名称是随机的。 public class Eczema extends Thread {
我读了this在那里发布并遵循指南。但这没有帮助;当该字段存在时,我得到 NoSuchFieldException。示例代码如下: 这是我的代码: class A{ private Strin
我在尝试运行以下方法时收到 java.lang.NoSuchFieldException: public void getTimes(String specialty, String day) {
现在,我正在用struts 2.8版本编写一个程序;当我在 struts.xml 文件中设置 devMode 时,如下所示 程序抛出异常: Throwable occurred: java.lang
使用 robolectric 进行 UnitTest 时,我收到错误 java.lang.NoSuchFieldException: sSystem 请给我一个建议。 描述 集成机器人电子错误 jav
当我开始为 Android 使用 greenDAO 时,这个问题已经发生了几个月。在我的应用程序中,我有 proguard 并且已经进行了 greenDAO 常见问题解答中建议的更改 -keepcla
java.lang.NoSuchFieldException: c at java.lang.Class.getDeclaredField(Unknown Source) at ru.onlymc.O
java.lang.NoSuchFieldException: id 下面一行正在创建异常。 String fieldValue =String.valueOf(studyplanCategory.g
我正在尝试使用 : 创建一个 spark session sparkSession = SparkSession.builder().appName(appName).master("local")
我叫 Matthew,在使用 ProGuard 后,我在 Android 上遇到了一些问题。 我在 libgdx 中编写游戏,我需要动态获取字符串,我有这样的东西: package com.PACKA
我目前正在将 hibernate-search 添加到一个大型现有项目中,但已经遇到了一个我似乎无法解决的问题。 我的问题归结为仅通过添加 hibernate-search 的 Maven 依赖项来引
我正在使用此代码更改我的 NumberPicker Utils.java: public static boolean setNumberPickerTextColor(NumberPicker nu
我是 Java 的新手,我看到了一个问答部分 here有两个例子,其中删除了可变性。经检测MutableString.java : import java.lang.reflect.Field; pu
public static B convert(A instance, Class targetClass) throws Exception
调试应用程序工作正常。 但是,当使用 minifyEnabled true 构建发布应用程序时,应用程序会崩溃。 当我从 3.4.1 升级到“com.android.tools.build:gradl
我试图通过单元测试设置环境变量,当我在本地计算机上运行代码时,它工作正常。 但是当我将它部署到 Jenkins 管道上时,它开始抛出异常。 异常:- java.lang.NoSuchFieldExce
我正在尝试运行此处提供的 kotlin 代码的测试:https://github.com/ligi/ipfs-api-kotlin与 gradlew 我收到下面列出的错误。有人能告诉我这个错误意味着什
我将 pig-0.11.0+28 与 CDH4 一起使用,当我运行任何 Pig 作业时,我都会遇到此异常。我也发生在本地模式下。有什么想法吗? 2013-07-08 13:53:44,035 [mai
我已经成功设置了spring-boot-groovytemplates和执行器项目。 但是,当将springloaded添加到buildscript / dependencies块时,在IDEA中重新
我真的很难弄明白这一点。当我查看 logcat 指向错误的位置时,它指向这一行: throw new RuntimeException(i); 在里面 public void onDetach() {
我是一名优秀的程序员,十分优秀!