[英]setBackground(): non-static method cannot be referenced from a static context
[英]non-static method getDeviceList() cannot be referenced from a static context
运行脚本时,我收到错误“无法从静态上下文中引用非静态方法 getDeviceList()” - 如何使该方法成为静态?
private static String getUsbDeviceAddress(String selection) {
String address = selection;
if (android.os.Build.VERSION.SDK_INT > 21) {
HashMap<String, UsbDevice> deviceList = UsbManager.getDeviceList();
for (UsbDevice device : deviceList.values()) {
if (device != null) {
String dsn = device.getSerialNumber();
if ((dsn != null) && !dsn.isEmpty()) {
if (selection.equalsIgnoreCase(dsn)) {
address = device.getDeviceName();
break;
}
}
}
}
}
return address;
}
getDeviceList() 方法不是静态的。你需要声明像
public static HashMap<String, UsbDevice> getDeviceList(){}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.