繁体   English   中英

不能从静态上下文中引用非静态方法 getDeviceList()

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM