Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.NoSuchMethodException:在棒棒糖上获取etherableIfaces_Java_Android_Android 5.0 Lollipop - Fatal编程技术网

java.lang.NoSuchMethodException:在棒棒糖上获取etherableIfaces

java.lang.NoSuchMethodException:在棒棒糖上获取etherableIfaces,java,android,android-5.0-lollipop,Java,Android,Android 5.0 Lollipop,我的应用程序需要检查是否有可用的USB连接接口。为此,它使用反射在ConnectionManager上调用GetEtherableIfaces ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Class cmClass = Class.forName(cm.getClass().getName()); Method method = cmC

我的应用程序需要检查是否有可用的USB连接接口。为此,它使用反射在ConnectionManager上调用GetEtherableIfaces

ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Class cmClass = Class.forName(cm.getClass().getName());
Method method = cmClass.getDeclaredMethod("getTetherableIfaces");
method.setAccessible(true);
method.invoke(cm, args); 
我已经在运行Android 5.0.1的LG Leon上测试过了,它失败了,出现了java.lang.NoSuchMethodException

棒棒糖中是否已删除或更改此功能?

根据该方法,此功能仍然存在


也许你应该试试
ConnectivityManager.class.getDeclaredMethod(“getEtherTableIfaces”)

您是否尝试查看connectivity manager的所有方法列表?你能给我们看一下下面代码的日志吗

Method[] methodArray = ConnectivityManager.class.getMethods();
for (Method method : methodArray) {
   Log.v(TAG, method.getName());
}

ConnectionManager.class.getDeclaredMethod有效,谢谢。调试完设备后,我发现context.getSystemService(context.CONNECTIVITY_SERVICE)返回ConnectivityManager的子类,在此实例上调用getDeclaredMethod只返回子类的方法,而不是ConnectivityManager中的方法。调用getMethod是正确的解决方案。