Non-static method ‘*‘ cannot be referenced from a static context (在静态上下文中不能引用非静态方法)

在静态上下文中不能引用非静态方法
原因:直接调用了其他包内的非静态方法。
解决方法:要有实例才能调用静态方法。

原本的代码

 public void onAttach(final UsbDevice device) {
            Toast.makeText(MainActivity.this, "USB_DEVICE_ATTACHED", Toast.LENGTH_SHORT).show();
            FileUtil.writeToFile("/sdcard/Android/data/test", "cameralist.txt", String.valueOf(UsbDevice.getProductId()));
        }

修改后

 public void onAttach(final UsbDevice device) {
            Toast.makeText(MainActivity.this, "USB_DEVICE_ATTACHED", Toast.LENGTH_SHORT).show();
            FileUtil.writeToFile("/sdcard/Android/data/test", "cameralist.txt", String.valueOf(device.getProductId()));
        }

总之。。。我犯的是一个很弱智的问题。如果你没有实例化一个对象,先实例化一个。

上一篇:kaggle住房预测项目——第1部分


下一篇:django进行数据库迁移的错误处理方法:You are trying to change the nullable field 'title' on book to non-nu