In android instrument test, when we want to add a resource file raw name to log,
it's supposed to be:

Resources.getResourceEntryName(resourceId)

But which shows an error:

non-static method cannot be referenced from a static context

And it is indeed:

public String getResourceEntryName(int resid) throws Resources.NotFoundException {        throw new RuntimeException("Stub!");    }

In fact we can do:

Context mContext = InstrumentationRegistry.getTargetContext();mContext.getResources().getResourceEntryName(resourceId)

You can't call something that doesn't exist. Since you haven't created an object, the non-static method doesn't exist yet. A static method (by definition) always exists.

The real problem is: getResourceEntryName() method itself is not static, it's an instance-level method, so we have to make an instance of Resources first.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android字节、十进制、十六进制、字符串
  2. Android(安卓)DatePickerDialog 只显示年
  3. Handler消息机制 源码解读
  4. 完美解决 No toolchains found in the ND
  5. Android动画AnimationSet遇到的问题。
  6. Flutter 在 Android(安卓)Studio下环境配
  7. Android开发中Material Design风格设置页
  8. Android(安卓)Studio的快捷键
  9. Android之常见图标尺寸
  10. 自定义字体主题+自定义背景+设置radiobut