public voID discoverServices() { Log.d(TAG,"Initializing discovery on NSD"); mNsdManager.discoverServices( SERVICE_TYPE,NsdManager.PROTOCol_DNS_SD,mdiscoveryListener);}@H_403_2@收到日志消息.经过一段时间(约5分钟),这是从程序输出:
05-21 11:08:32.518: E/NsdCamera(12236): discovery Failed: Error code:005-21 11:08:32.518: W/dalvikvm(12236): threadID=12: thread exiting with uncaught exception (group=0x40c9c930)05-21 11:08:32.518: E/AndroIDRuntime(12236): FATAL EXCEPTION: NsdManager05-21 11:08:32.518: E/AndroIDRuntime(12236): java.lang.NullPointerException05-21 11:08:32.518: E/AndroIDRuntime(12236): at androID.net.nsd.NsdManager$ServiceHandler.handleMessage(NsdManager.java:338)05-21 11:08:32.518: E/AndroIDRuntime(12236): at androID.os.Handler.dispatchMessage(Handler.java:99)05-21 11:08:32.518: E/AndroIDRuntime(12236): at androID.os.Looper.loop(Looper.java:137)05-21 11:08:32.518: E/AndroIDRuntime(12236): at androID.os.HandlerThread.run(HandlerThread.java:60)@H_403_2@还来自服务:
05-21 11:50:49.108: E/NativeDaemonConnector.ResponseQueue(8858): Timeout waiting for response05-21 11:50:49.108: E/mDnsConnector(8858): timed-out waiting for response to 10 mdnssd discover 6 _http._tcp.05-21 11:50:49.108: E/NsdService(8858): Failed to discoverServices com.androID.server.NativeDaemonConnector$NativeDaemonFailureException: command '10 mdnssd discover 6 _http._tcp.' Failed with 'null'@H_403_2@错误代码“0”在NSDManager class中描述为内部错误.
我做的主要更新是访问名为NsdCamera的helper类中的上下文.
这里有一些可能是邪恶的代码片段: @H_403_2@助手级构造函数:
public NsdCamera(CameraChooseActivity context) { mContext = context; updateUI = new UpdateUI(); mNsdManager = (NsdManager) context.getSystemService(Context.NSD_SERVICE); mServicename = new Vector<NsdServiceInfo>();@H_403_2@Helper级NSD初始化:
public voID initialiZensd() { initializediscoveryListener();}public voID initializediscoveryListener() { mdiscoveryListener = new NsdManager.discoveryListener() { @OverrIDe public voID ondiscoveryStarted(String regType) { Log.d(TAG,"Service discovery started"); } /** * A name check to see if the DNS discovery was correct. Checks if it contains * AXIS and has the desired MAC address-space * @param hostname,the inputted hostname from the discovery cycle * @return true if it's an Axis camera. */ public boolean nameCheck(String hostname){ return (hostname.contains("AXIS") && hostname.contains("00408C")); } @OverrIDe public voID onServiceFound(NsdServiceInfo service) { Log.d(TAG,"Service discovery success: " + service.getServicename()); if (!service.getServiceType().equals(SERVICE_TYPE)) { Log.d(TAG,"UnkNown Service Type: " + service.getServiceType()); } else if (nameCheck(service.getServicename())){ mServicename.add(service);// updateUI.execute(new BundleUI(mContext,service,null)); } } @OverrIDe public voID onServiceLost(NsdServiceInfo service) { Log.e(TAG,"service lost" + service); if(mServicename.remove(service)){ //Todo Log.e(TAG,"remove the vIEw,service is lost"); } } @OverrIDe public voID ondiscoveryStopped(String serviceType) { Log.i(TAG,"discovery stopped: " + serviceType); //Necessary?? mServicename.clear(); } @OverrIDe public voID onStartdiscoveryFailed(String serviceType,int errorCode) { Log.e(TAG,"discovery Failed: Error code:" + errorCode); mNsdManager.stopServicediscovery(this); } @OverrIDe public voID onStopdiscoveryFailed(String serviceType,"discovery Failed: Error code:" + errorCode); mNsdManager.stopServicediscovery(this); } };}@H_403_2@CameraChooseActivity – > onCreate正在调用helper-class
protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_camerachoose); //Setup the animation for the text in the relativelayout mDescription = (TextSwitcher) findVIEwByID(R.ID.camera_add); mDescription.setFactory(this); mDescription.setInAnimation(AnimationUtils.loadAnimation(this,androID.R.anim.fade_in)); mDescription.setoutAnimation(AnimationUtils.loadAnimation(this,androID.R.anim.fade_out)); mDescription.setText(getText(R.string.camera_add)); //Building alert dialog mBuilder = new AlertDialog.Builder(this,AlertDialog.theme_HolO_DARK); mBuilder.setMessage(R.string.dialog_about).setTitle(R.string.action_about); mBuilder.setIcon(androID.R.drawable.ic_dialog_info); mLayout = (relativeLayout) findVIEwByID(R.ID.layout_camerachoose); //Initialize the NSD mNSDHelper = new NsdCamera(this); mNSDHelper.initialiZensd();解决方法 根据我的经验,我认为这是一个听众终身问题. @H_403_2@因为您为系统NSD服务提供了两个侦听器,一个用于startServicediscovery(),另一个用于stopServicediscovery().当系统访问这些侦听器时,您需要确保这些侦听器仍处于活动状态. @H_403_2@一个事实是,在调用startServicediscovery()2分钟后调用onStartdiscoveryFailed(),与侦听器的生命周期相比,它应该是一个很长的时间. @H_403_2@因此,如果侦听器是本地对象并在调用startServicediscovery()之后释放,则可能导致NSD服务崩溃.
@H_403_2@public voID stopServicediscovery (NsdManager.discoveryListener@H_403_2@并在下面的代码段确保不要调用任何NsdManager API.
Listener) @H_403_2@Stop service discovery initiated with discoverServices(). An active
service discovery is notifIEd to the application with
ondiscoveryStarted(String) and it stays active until the application
invokes a stop service discovery. A successful stop is notifIEd to
with a call to ondiscoveryStopped(String). @H_403_2@Upon failure to stop service discovery,application is notifIEd
through onStopdiscoveryFailed(String,int). @H_403_2@Parameters Listener This should be the Listener object that was passed
to discoverServices(String,int,NsdManager.discoveryListener). It
IDentifIEs the discovery that should be stopped and notifIEs of a
successful stop.
@OverrIDepublic voID onStartdiscoveryFailed(String serviceType,int errorCode) { Log.i(TAG,"onStartdiscoveryFailed : Error code:" + errorCode);}@OverrIDepublic voID onStopdiscoveryFailed(String serviceType,int errorCode) { Log.i(TAG,"onStopdiscoveryFailed : Error code:" + errorCode);}@H_403_2@祝好运. 总结
以上是内存溢出为你收集整理的在Android中使用网络服务发现的内部错误全部内容,希望文章能够帮你解决在Android中使用网络服务发现的内部错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)