尝试使用Android RTP时收到错误消息。

Error:(49, 55) error: incompatible types: Object cannot be converted to NetworkInterface
Error:(51, 69) error: incompatible types: Object cannot be converted to InetAddress


我的代码是这样的

for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement(); //first error message
            for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement(); //second error message
                if (!inetAddress.isLoopbackAddress()) {
                    ip= inetAddress.getAddress();
                }
            }
        }

最佳答案

更换:

for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {


与:

for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {


并替换:

for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {


与:

for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {

关于java - Android RTP。不兼容的类型:无法转换对象。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43937719/

10-12 14:00