samedi 28 mars 2015

java.lang.IllegalStateException: Could not execute method of the activity android

I'm pretty new to Android, and I'm trying to connect to a server on port 25000, and send a String, but when I try, I get an error:



package com.nowebsite.www.myapplication;

import java.io.*;
import java.net.*;

public class PanelSend{

static String serverurl = "Ip Adress";
static int serverport = 25000;

public static void SendCommand(String Command){
Socket socket = null;
try{
System.out.println("Connecting to " + serverurl + " on port " + serverport);
socket = new Socket(serverurl,serverport);
socket.setSoTimeout(10000);
System.out.println("Connected.");
InputStreamReader inputstreamreader = new InputStreamReader(socket.getInputStream());
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
PrintWriter printwriter = new PrintWriter(socket.getOutputStream(),true);
printwriter.println(Command);
String lineread = "";
if ((lineread = bufferedreader.readLine()) != null){
System.out.println("Received from Server: " + lineread);
}
System.out.println("Closing connection.");
bufferedreader.close();
inputstreamreader.close();
printwriter.close();
socket.close();

}catch(UnknownHostException unhe){
System.out.println("UnknownHostException: " + unhe.getMessage());
}catch(IOException ioe){
System.out.println("IOException: " + ioe.getMessage());
}finally{
/* try{
socket.close();//removed because this line was giving me an error
}catch(IOException ioe){
System.out.println("IOException: " + ioe.getMessage());
}*/
}
}
}


and my AndroidManifest.xml



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.nowebsite.www.myapplication" >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>


When I try to use the code, I get this http://ift.tt/1NqV52U all help would be appreciated :)


Aucun commentaire:

Enregistrer un commentaire