嘿所有,我正在做一个远程控制我的遥控车的项目,安装了adruino板并且非常谨慎。 wifly shied有自己的网络服务器设置,并设置向上,向下,向左和向右移动的配置。但是,当我点击我的前进按钮时,我的Android应用程序中有关于如何访问网络服务器的问题。下面是示例代码,我从那里停留。
public class GetUrl extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View forward_Button = findViewById(R.id.forwardButton);
forward_Button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.forwardButton:
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://192.168.1.3/?LED=Fowd");
HttpResponse response = httpclient.execute(httpget);
break;
答案 0 :(得分:0)
JAVA 101:httpclient.execute(httpget);抛出你必须抓住的异常:
try {
httpclient.execute(httpget);
} catch (ClientProtocolException e) {
e.printStackStrace();
}