- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
java.lang.NoSuchFieldException: id
下面一行正在创建异常。
String fieldValue =String.valueOf(studyplanCategory.getClass().getField(filterProperty).get(studyplanCategory));
studyplanCategory 是一个有效的对象并且有实际值。由于此异常,我的 JSF web 应用程序的 LazyLoading DataTable 中的加载方法和搜索功能无法正常工作。
最佳答案
来自Javadoc对于 Class.getField(...)
:
Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object. The name parameter is a String specifying the simple name of the desired field. The field to be reflected is determined by the algorithm that follows. Let C be the class represented by this object:
If C declares a public field with the name specified, that is the field to be reflected. If no field was found in step 1 above, this algorithm is applied recursively to each direct superinterface of C. The direct superinterfaces are searched in the order they were declared. If no field was found in steps 1 and 2 above, and C has a superclass S, then this algorithm is invoked recursively upon S. If C has no superclass, then a NoSuchFieldException is thrown. See The Java Language Specification, sections 8.2 and 8.3.
如果您尝试通过以下方式检索字段:
studyplanCategory.getClass().getField(filterProperty)
是私有(private)的,那么你会得到一个NoSuchFieldException
。对于私有(private)字段,试试这个:
studyplanCategory.getClass().getDeclaredField(filterProperty)
并以这种方式通过字段设置值时绕过潜在的非法访问异常:
Field field = studyplanCategory.getClass().getDeclaredField(filterProperty);
field.setAccessible(true);
field.get(studyplanCategory);
关于java - getClass().getField() 上的 NoSuchFieldException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10315614/
对于我的应用程序,我需要能够找到类型(不是实例)的字段列表以及运行时这些字段的类型。到目前为止,我只能获得一个包含classOf[MyCaseClass].getMethods的getter的case
我正在尝试在个人资料页面上显示用户行中的点。我尝试使用以下内容 getField('points');?> 拉出包含用户点的字段,但没有为我正在测试的用户显示任何内容。我正在测试它,以设置了 16 点
问题:我希望用户输入一种颜色(红色、蓝色)并将其转换为与颜色一起使用 我一直在看这个 Getting a Color from a String input ,我知道最好使用 JColorChoose
谁能看出我在下面做错了什么?该类型具有服务方法试图访问的公共(public)属性,那么为什么它没有被反射拾取? Public class SomeClass { private YetAnoth
我正在尝试 getField 但总是返回 null这是代码的图像和变量的监视。 代码:FieldInfo xSortField = xFieldInfo.GetValue(x).GetType().G
我试图反射(reflect)派生类型中的字段,但它返回的字段基本类型。 public class basetype { string basevar; } public class deriv
我目前正在尝试将 Xamarin.iOS 应用程序库转换为 PCL。我有这段无法编译的代码: private void SetPrivateField(object item, string
我希望能够为用户定义的类型创建一个调度,该类型本质上将进行就地复制。但是,我想以一种类型稳定的方式来做,因此我想避免使用 getfield直接,而是尝试使用生成的函数。像这样的类型是否可能 type
我注意到在调用 GetFields() 时在枚举类型上,我得到了一个 int32 类型的额外字段。它从哪里来的?? 当我调用另一个重载 (GetFields(System.Reflection.Bin
我试图了解 Mirrors Api 的工作原理。具体来说,如何从它的Symbol中获取一个字段的值, 使用 getField . 对于getField方法,它应该适用于任何 Symbol这是一个 se
我有一个示例类: public class A { public int x; } 如果我要做如下的事情: Class a = Class.forName("A"); for (Field f
如果我通过 Assembly.Load 加载程序集,我可以迭代其类型,通过 typef(...).IsAssignableFrom 查找特定类型,并通过 GetField 从类型中获取字段信息。 当我
public string[] tName = new string[]{"Whatever","Doesntmatter"}; string vBob = "Something"; string[]
我已将 720 张新图像添加到我的 Drawable 文件夹中,但是当我使用 Field[] drawables = android.R.drawable.class.getFields() 时,没有
在我目前正在处理的项目中,我偶然发现了这个问题: 我想创建类“ApiID”的实例。我从 Reflector 获得了代码,如您所见,.dll(不是我的项目)导入来自非托管代码,我无权访问。 [S
Class.getFields() 的 Javadoc 说:“返回的数组中的元素未排序且未按任何特定顺序排列。” 关于订单实际如何确定的任何提示?有没有可能当我两次执行这个方法时,我得到的字段顺序不同
这段旧代码在使用反射的方法调用中返回一个用属性修饰的字段列表 有没有办法用 TypeDescripter 或 LINQ 替换它? public static FieldInfo[] GetFi
我正在尝试检索对象的公共(public)属性,但它没有返回任何内容。你能告诉我我做错了什么吗? public class AdHocCallReportViewModel : ReportViewMo
我正在尝试实现一个位于 https://github.com/jbogard/presentations/blob/master/WickedDomainModels/After/Model/Enum
C#,网络 2.0 这是代码(我取出了所有特定于域的内容,它仍然返回一个空数组): using System; using System.Collections.Generic; using Syst
我是一名优秀的程序员,十分优秀!