Java Android和arduino
我有这段代码,但读到不支持Java Android和arduino,java,android,arduino,Java,Android,Arduino,我有这段代码,但读到不支持httpclient,现在我必须使用httpconnection,所以我读了文档,但无法使其工作。您的日志上有任何错误吗?错误:(31,13)错误:找不到符号类HttpClientError:(31,41)错误:找不到符号类DefaultHttpClientError:(32,36)错误:找不到符号类HttpGetError:任务:app:compileReleaseJavaWithJavac的执行失败。“>编译失败;有关详细信息,请参阅编译器错误输出。您的Logcat
httpclient
,现在我必须使用httpconnection
,所以我读了文档,但无法使其工作。您的日志上有任何错误吗?错误:(31,13)错误:找不到符号类HttpClientError:(31,41)错误:找不到符号类DefaultHttpClientError:(32,36)错误:找不到符号类HttpGetError:任务:app:compileReleaseJavaWithJavac的执行失败。“>编译失败;有关详细信息,请参阅编译器错误输出。您的Logcat上是否有任何错误?错误:(31,13)错误:找不到符号类HttpClientError:(31,41)错误:找不到符号类DefaultHttpClientError:(32,36)错误:找不到符号类HttpGetError:任务执行失败:app:compileReleaseJavaWithJavac'>编译失败;有关详细信息,请参阅编译器错误输出。
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View led1on = findViewById(R.id.led_1on);
View led1off = findViewById(R.id.led_1off);
View led2on = findViewById(R.id.led_2on);
View led2off = findViewById(R.id.led_2off);
led1on.setOnClickListener(this);
led1off.setOnClickListener(this);
led2on.setOnClickListener(this);
led2off.setOnClickListener(this);
}
public void commandArduino(String url){
try {
HttpClient httpclient = new DefaultHttpClient();
httpclient.execute(new HttpGet(url));
} catch (Exception e) {
}
}
public void onClick(View thisView) {
switch(thisView.getId()){
case R.id.led_1on:
commandArduino("http://192.168.0.15/?cmd=1");
Toast.makeText(getApplicationContext(), "led_1on",Toast.LENGTH_LONG).show();
break;
case R.id.led_1off:
commandArduino("http://192.168.0.15/?cmd=2");
Toast.makeText(getApplicationContext(), "led_1off",Toast.LENGTH_LONG).show();
break;
case R.id.led_2on:
commandArduino("http://192.168.0.15/?cmd=3");
Toast.makeText(getApplicationContext(), "led_2on",Toast.LENGTH_LONG).show();
break;
case R.id.led_2off:
commandArduino("http://192.168.0.15/?cmd=4");
Toast.makeText(getApplicationContext(), "led_2off",Toast.LENGTH_LONG).show();
break;
}
}
}