안드로이드 개발 질문/답변
(글 수 45,052)
버튼을 클릭했을때 서버에서 문자열을 받아서 출력하는 소스입니다
하지만 클릭시에 알수없는 문제가 발생되네요 도움점;;
package com.ABP;
import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import com.ABP.Constants;
import com.ABP.R;
public class Main extends Activity {
private static final String CLASSTAG = Main.class.getSimpleName();
private String ipAddress = "192.168.0.34";
private String port = "9900";
private String socketInput = "get";
private TextView socketOutput;
private Button socketButton;
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
this.setContentView(R.layout.main);
this.socketOutput = (TextView) findViewById(R.id.socket_output);
this.socketButton = (Button) findViewById(R.id.socket_button);
this.socketButton.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
socketOutput.setText("");
String output = callSocket(ipAddress, port, socketInput);
socketOutput.setText(output);
}
});
}
private String callSocket(final String ip, final String port, final String socketData) {
Socket socket = null;
BufferedWriter writer = null;
BufferedReader reader = null;
String output = null;
try {
socket = new Socket(ip, Integer.parseInt(port));
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String input = socketData;
writer.write(input+ "\n", 0, input.length() + 1);
writer.flush();
output = reader.readLine();
Log.d(Constants.LOGTAG, " " + Main.CLASSTAG + " output - " + output);
writer.write("EXIT\n", 0, 5);
writer.flush();
} catch (IOException e) {
Log.e(Constants.LOGTAG, " " + Main.CLASSTAG + " IOException calling socket", e);
} finally {
try {
writer.close();
} catch (IOException e) {
// swallow
}
try {
reader.close();
} catch (IOException e) {
// swallow
}
try {
socket.close();
} catch (IOException e) {
// swallow
}
}
return output;
};
}



ㄷㄷ 어떤 에러가 발생한지를 알아야 찾기가 쉬울텐데요...
그냥 알수없는 문제라고 하시면...
Logcat이나 debug에 에러가 발생했을때 어떤 메세지가 출력됐는지
같이 올리시면 사람들이 문제점을 찾기 쉬울것같네요ㅋ
근데....socketKeyOut 랑 socketButton앞에 this들하고
함수에 전부 final을 붙이신 이유가?