Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.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
在android P2P中尝试断开连接时应用程序崩溃_Android_Wifi Direct - Fatal编程技术网

在android P2P中尝试断开连接时应用程序崩溃

在android P2P中尝试断开连接时应用程序崩溃,android,wifi-direct,Android,Wifi Direct,我正在尝试实现google的wifidirect连接示例。一切正常,但在选项菜单上,如果我单击“断开连接”,应用程序将崩溃并出现“nullpointer异常”。错误显示在行“mconnecion.teardown()”上 “mconnection”是一个类,“teardown()”方法如下所示 public void tearDown() { mChatServer.tearDown(); mChatClient.tearDown(); isReady = false; mContext = n

我正在尝试实现google的wifidirect连接示例。一切正常,但在选项菜单上,如果我单击“断开连接”,应用程序将崩溃并出现“nullpointer异常”。错误显示在行“mconnecion.teardown()”上

“mconnection”是一个类,“teardown()”方法如下所示

public void tearDown() {
mChatServer.tearDown();
mChatClient.tearDown();
isReady = false;
mContext = null;
}

我怎样才能解决这个问题

它显示空指针异常,因为那里的对象为空。检查对象是否为空,并且问题不应存在

if (mConnection!=null)
    mConnection.tearDown();
    mConnection=null;
    return true;

这应该可以解决您的问题,我希望它显示空指针异常,因为那里的对象是空的。检查对象是否为空,并且问题不应存在

if (mConnection!=null)
    mConnection.tearDown();
    mConnection=null;
    return true;
我希望这能解决你的问题