-1
wifi 네트워크를 통해 간단한 UDP 메시지를 보내고 받으려고합니다. 다음 코드를 사용하고 있습니다. 내 wifi 네트워크가 잘 작동하고 소켓 변수를 초기화했습니다 그럼 또한 때마다 내가 null 포인터 예외가 수신 방법에있어. 도와주세요.UDP 수신 함수가 nullpointerexception을 던지고
public void run() {
// TODO Auto-generated method stub
WifiConfiguration conf=new WifiConfiguration();
String networkSSID="Lenovo S920";
String pass="12345678saz";
conf.SSID = "\"" + networkSSID + "\"";
conf.preSharedKey = "\"" + pass + "\"";
conf.status = WifiConfiguration.Status.ENABLED;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
byte[] buf = new byte[1024];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
try {
serverSocketUDP.receive(packet);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(NetworkOnMainThreadException e) {
e.printStackTrace();
}
언제 어떻게 serverSocketUDP가 초기화됩니까? 이것이 누락 된 관련 코드입니다. – Peter