![](/img/trans.png)
[英]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.