非静态方法getDeviceList()无法从静态上下文中引用。

huangapple 未分类评论53阅读模式
英文:

non-static method getDeviceList() cannot be referenced from a static context

问题

  1. 当运行脚本时我收到错误消息"非静态方法 getDeviceList() 无法从静态上下文引用" - 如何将此方法改为静态
  2. private static String getUsbDeviceAddress(String selection) {
  3. String address = selection;
  4. if (android.os.Build.VERSION.SDK_INT > 21) {
  5. HashMap<String, UsbDevice> deviceList = UsbManager.getDeviceList();
  6. for (UsbDevice device : deviceList.values()) {
  7. if (device != null) {
  8. String dsn = device.getSerialNumber();
  9. if ((dsn != null) && !dsn.isEmpty()) {
  10. if (selection.equalsIgnoreCase(dsn)) {
  11. address = device.getDeviceName();
  12. break;
  13. }
  14. }
  15. }
  16. }
  17. }
  18. return address;
  19. }
英文:

When running script I receive the error "non-static method getDeviceList() cannot be referenced from a static context" - How do I make this method static?

  1. private static String getUsbDeviceAddress(String selection) {
  2. String address = selection;
  3. if (android.os.Build.VERSION.SDK_INT &gt; 21) {
  4. HashMap&lt;String, UsbDevice&gt; deviceList = UsbManager.getDeviceList();
  5. for (UsbDevice device : deviceList.values()) {
  6. if (device != null) {
  7. String dsn = device.getSerialNumber();
  8. if ((dsn != null) &amp;&amp; !dsn.isEmpty()) {
  9. if (selection.equalsIgnoreCase(dsn)) {
  10. address = device.getDeviceName();
  11. break;
  12. }
  13. }
  14. }
  15. }
  16. }
  17. return address;
  18. }

答案1

得分: 0

getDeviceList() 方法不是静态的。您需要像这样声明:

  1. public static HashMap<String, UsbDevice> getDeviceList(){}
英文:

getDeviceList() method not static.You need to declare like

  1. public static HashMap&lt;String, UsbDevice&gt; getDeviceList(){}

huangapple
  • 本文由 发表于 2020年3月16日 10:15:42
  • 转载请务必保留本文链接:https://java.coder-hub.com/60699565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定