连接到数据库时,java.lang.IllegalStateException目标主机不得为空
我正在尝试连接到计算机上的连接到数据库时,java.lang.IllegalStateException目标主机不得为空,java,php,android,mysql,database,Java,Php,Android,Mysql,Database,我正在尝试连接到计算机上的localhost/myfile.php。PHP文件将数据库数据转换为JSON,我希望在连接后对其进行解析。当我尝试连接时,我会 Target host must not be null, or set in parameters. scheme=null, host=null, path=10.0.0.9/myfile.php 有什么想法吗 public void getData(){ String result = ""; InputStre
localhost/myfile.php
。PHP文件将数据库数据转换为JSON
,我希望在连接后对其进行解析。当我尝试连接时,我会
Target host must not be null, or set in parameters. scheme=null, host=null,
path=10.0.0.9/myfile.php
有什么想法吗
public void getData(){
String result = "";
InputStream isr = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("10.0.0.9/myfile.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
}
catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
resultView.setText("Couldnt connect to database" + e);
看起来您缺少URI方案
尝试使用
新的HttpPost(“http://10.0.0.9/myfile.php");代码>目标错误是来自客户端Java还是服务器上的php程序?@user2976670您确定异常是相同的吗?“连接到数据库的目标主机不得为空”正好在方案丢失时发生。它确实解决了异常,但仍然无法正常工作。但你是对的,thanks@user2976670很高兴听到这个消息。那么请接受答案;)