我正在尝试使用 WiFip2p 创建一个聊天应用程序。一切都在这个应用程序中完成。在发送和接收消息应用程序运行良好之前。在那之后,我得到了这个错误。当我连接到另一台设备时出现此错误。它显示了一个空对象引用。我不知道为什么我需要一个解决方案,任何人都可以帮助我谢谢。
public class WiFi_Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wi_fi_);
FINDVIEWBYID();
CLICKLISTINER();
}
Handler handler=new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
switch (msg.what)
{
case MESSAGE_READ:
byte[] readbuffer=(byte[])msg.obj;
String tempmez=new String(readbuffer,0,msg.arg1);
txt_message.setText(tempmez);
break;
}
return true;
}
});
private void FINDVIEWBYID() {
btn_onoff=findViewById(R.id.onOff);
btn_discover=findViewById(R.id.discover);
btn_send=findViewById(R.id.sendButton);
listView=findViewById(R.id.peerListView);
txt_connectionsts=findViewById(R.id.connectionStatus);
txt_message=findViewById(R.id.readMsg);
edit_message=findViewById(R.id.writeMsg);
wifiManager= (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiP2pManager= (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
channel=wifiP2pManager.initialize(this,getMainLooper(),null);
broadcastReceiver=new Wifi_broadcast_reciever(wifiP2pManager,channel,this);
intentFilter=new IntentFilter();
intentFilter.addAction(wifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(wifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter.addAction(wifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter.addAction(wifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
}
慕勒3428872
至尊宝的传说
相关分类