我想开发一个Android应用程序,它可以与我的服务器进行通信,这是使用Apache thrift开发的...我怎样才能开发plz帮助我,我写一个代码,但它无法成功运行....
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class ThriftExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{<br> //this code is used to cretae an client
TTransport transport = new TSocket("107.20.177.28", 8888);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
Mainservice.Client client = new Mainservice.Client(protocol);
//upto this line is common code for client need not to touch
//below call any API using client object created above
//like I have call add API which take some input and return output
System.out.println(client);
Getsearch g=new Getsearch();
g.rows="5";
g.text="india";
g.page=Integer.toString(2);
Toast.makeText(getBaseContext(), client.get_search(g).toString(), <br>Toast.LENGTH_LONG).show();
System.out.println(client.get_search(g));
//System.out.println("The Sum is: "+sum);
//close client socket
transport.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}