संदेश को सॉकेट पर भेजे जाने के बाद मैं एक टोस्ट प्रदर्शित करना चाहता हूं। इसके बाद "लॉग.d (" क्लाइंट एक्टिविटी "," सी: प्रेषित ");"हैंडलर/थ्रेड के अंदर टोस्ट कैसे प्रदर्शित करें?
क्या मुझे टोस्ट प्रदर्शित करने के लिए एक अलग धागा बनाने की आवश्यकता है?
public class ClientActivity extends Activity {
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.client);
serverIp = (EditText) findViewById(R.id.EditText01);
message =(EditText) findViewById(R.id.EditText02);
connectPhones = (Button) findViewById(R.id.Button01);
}
public void Click1(View v) {
if (!connected) {
serverIpAddress = serverIp.getText().toString();
if (!serverIpAddress.equals("")) {
Thread cThread = new Thread(new ClientThread());
cThread.start();
}
}
}
private class ClientThread implements Runnable {
public void run() {
try {
InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
Log.d("ClientActivity", "C: Connecting...");
Socket socket = new Socket(serverAddr, ServerActivity.SERVERPORT);
connected = true;
while (connected) {
try {
if(i>5)
{
}
else
{
Log.d("ClientActivity", "C: Sending command.");
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream())), true);
// where you issue the commands
message1= message.getText().toString();
out.println(message1);
i=i+1;
Log.d("ClientActivity", "C: Sent.");
}
} catch (Exception e) {
Log.e("ClientActivity", "S: Error", e);
}
}
socket.close();
Log.d("ClientActivity", "C: Closed.");
} catch (Exception e) {
Log.e("ClientActivity", "C: Error", e);
connected = false;
}
}
}
}
घोषित करने और अपने मुख्य गतिविधि में हैंडलर ऑब्जेक्ट को प्रारंभ (धागा बाहर) करने के लिए यह अभी भी फेंकता है:
तो एक टोस्ट प्रदर्शित करने के लिए अपनी गतिविधि में ऐसा एक त्रुटि संदेश "विधि टोस्ट (संदर्भ, charSequence, int) प्रकार टोस्ट में विधि के लिए लागू नहीं है (नया रननेबल() {}, स्ट्रिंग, int)" – Shan
त्रुटि क्या है? – 5hssba
त्रुटि जोड़ा गया – Shan