2 bbenchild bbenchild 于 2014.09.30 17:27 提问

android.net.nsd 发现服务时随机重启报错 dequeueBuffer failed

小弟最近在做安卓的开发,用了android.net.nsd的服务注册与发现。在模拟器上调试的时候没有发现任何问题。但是将demo放到智能电视的时候出了问题。程序有时正常有时会重启。进过不断的调试发现是在启动NSD服务发现的时候报错了。

报错信息如下:
09-30 15:10:56.760: I/sg_life(11572): start discover……
09-30 15:10:56.760: V/ActivityThread(11572): Resume ActivityRecord{41664cf8 token=android.os.BinderProxy@41664490 {com.example.testapk/com.example.testapk.ui.MDEActivity}} started activity: false, hideForNow: false, finished: false
09-30 15:10:56.768: V/ActivityThread(11572): Scheduling idle handler for ActivityRecord{41664cf8 token=android.os.BinderProxy@41664490 {com.example.testapk/com.example.testapk.ui.MDEActivity}}
09-30 15:10:56.856: E/SurfaceTextureClient(11572): dequeueBuffer failed (No such device)
09-30 15:10:56.864: E/ViewRootImpl(11572): Could not lock surface
09-30 15:10:56.864: E/ViewRootImpl(11572): java.lang.IllegalArgumentException
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.Surface.nativeLockCanvas(Native Method)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.Surface.lockCanvas(Surface.java:452)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2264)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2227)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2095)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1904)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1039)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4417)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.Choreographer.doFrame(Choreographer.java:532)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.os.Handler.handleCallback(Handler.java:725)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.os.Looper.loop(Looper.java:137)
09-30 15:10:56.864: E/ViewRootImpl(11572): at android.app.ActivityThread.main(ActivityThread.java:5061)
09-30 15:10:56.864: E/ViewRootImpl(11572): at java.lang.reflect.Method.invokeNative(Native Method)
09-30 15:10:56.864: E/ViewRootImpl(11572): at java.lang.reflect.Method.invoke(Method.java:511)
09-30 15:10:56.864: E/ViewRootImpl(11572): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
09-30 15:10:56.864: E/ViewRootImpl(11572): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
09-30 15:10:56.864: E/ViewRootImpl(11572): at dalvik.system.NativeStart.main(Native Method)
09-30 15:10:57.424: E/InputEventReceiver(11572): channel '41c547b0 com.example.testapk/com.example.testapk.ui.MainActivity (client)' ~ Publisher closed input channel or an error occurred. events=0x9
09-30 15:10:57.600: E/InputEventReceiver(11572): channel '41b6a120 com.example.testapk/com.example.testapk.ui.MDEActivity (client)' ~ Publisher closed input channel or an error occurred. events=0x9

代码如下:

public void discoverServices() {
    Log.i("sg_life", "start discover……");
    mNsdManager.discoverServices(SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD,
            mDiscoveryListener);
}

日志中第一行是调用discoverServices之前的日志,在mDiscoveryListener的onDiscoveryStarted方法里也加了输出但是日志上没有打出来。

        public void onDiscoveryStarted(String regType) {
            Log.e("sg_life", "Service discovery started……");
        }

因此暂时判断是discoverServices方法中出错。API中discoverServices方法如下

public void discoverServices(String serviceType, int protocolType, DiscoveryListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("listener cannot be null");
    }
    if (TextUtils.isEmpty(serviceType)) {
        throw new IllegalArgumentException("Service type cannot be empty");
    }

    if (protocolType != PROTOCOL_DNS_SD) {
        throw new IllegalArgumentException("Unsupported protocol");
    }

    NsdServiceInfo s = new NsdServiceInfo();
    s.setServiceType(serviceType);
    mAsyncChannel.sendMessage(DISCOVER_SERVICES, 0, putListener(listener, s), s);
}

再之后的代码小弟也没能力找到,根据报错日志也没有找到有用的信息。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!