다음 Android 코드가 있습니다. Android 앱이 소켓 프로그램에 연결되어 있고 스레드 모델에서 결과가 "성공"으로 표시됩니다. 그 후 경고 대화 상자를 표시하려고 시도하지만 안드로이드 프로그램에서 예외가 발생합니다. thread exiting with uncaught exception
여기서 잘못된 정보를 얻을 수 없습니다. 스레드 내에 경고를 표시 할 수 있습니까? 제발 조언.Android : 소켓 대화 상자 내에서 알림 대화 상자에서 예외가 발생합니다.
public class RandomIDActivity extends Activity {
.............
clientthread = new ClientThread();
Button connectBtn = (Button) findViewById(R.id.button2);
connectBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Thread t = new Thread(new ClientThread());
t.start();
}
});
}
class ClientThread implements Runnable {
@Override
public void run()
{
// We got this IP from servlet and stored temporarily, so retrieve it from there.
String socketServerIP = ((GlobalStore) RandomIDActivity.this.getApplication()).getSocketIPAddress();
Log.d("socketServerIP", socketServerIP);
try {
InetAddress serverAddr = InetAddress.getByName(socketServerIP);
socket = new Socket(serverAddr, SERVERPORT);
pw = new PrintWriter(socket.getOutputStream(), true);
EditText randTxtField = (EditText) findViewById(R.id.editText1);
pw.println(randTxtField.getText().toString());
//output.write(imgbyte,0,imgbyte.length);
pw.flush();
// Read randrom ID returned by Socket
BufferedReader socketReader;
try {
socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
msgStr = socketReader.readLine();
Log.d("msgStr: ", msgStr);
if (msgStr.equalsIgnoreCase("SUCCESS"))
{
socket.close();
// Crashing if I call alert dialog like this.
CobrowseAlertDialog("Successfully connected! Click OK to starts screen sharing!", true);
//Intent intent = new Intent(context, MainActivity.class);
//startActivity(intent);
}
else
{
CobrowseAlertDialog("There seems to be problem in connecting..Try connecting it again with proper Random Auth ID!", false);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (UnknownHostException e1) {
e1.printStackTrace();
}
catch (IOException e1) {
e1.printStackTrace();
}
}
}
public void CobrowseAlertDialog(String msg, boolean bMove) {
AlertDialog.Builder builder = new AlertDialog.Builder(RandomIDActivity.this); // getParent()
builder.setTitle("Cobrowsing")
.setMessage(msg)
.setCancelable(false)
.setNegativeButton("Ok",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
//Intent intent = new Intent(context, MainActivity.class);
//startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
로그 캣 :
03-24 17:12:20.353: D/socketServerIP(32717): 192.168.1.21
03-24 17:12:20.503: D/msgStr:(32717): SUCCESS
03-24 17:12:29.952: W/dalvikvm(32717): threadid=17: thread exiting with uncaught exception (group=0x415efba8)
03-24 17:12:33.926: W/jdwp(32717): Debugger is telling the VM to exit with code=1
로그 고양이주세요! –
메인 스레드에서만 경고 대화 상자를 표시 할 수 있습니다. logcat 여기에 게시 –
로그 고양이를 업데이트했습니다. – Stella