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

问题描述 投票:0回答:1

运行脚本时收到错误消息“无法从静态上下文引用非静态方法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;
    }
java android methods
1个回答
0
投票

getDeviceList()方法不是静态的。您需要像]一样声明>

   public static HashMap<String, UsbDevice>  getDeviceList(){}
© www.soinside.com 2019 - 2024. All rights reserved.