java.lang.IllegalStateException 连接到数据库的目标主机不能为空

标签 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 = "";
    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 方案。

尝试使用 new HttpPost("http://10.0.0.9/myfile.php");

关于java.lang.IllegalStateException 连接到数据库的目标主机不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23748233/

相关文章:

android - 在微调器中设置位置

android - Qt/Android/CMake : Custom AndroidManifest. xml 未考虑在内

java - HTTP 状态 403 - 未找到预期的 CSRF token

php - .htaccess 将子域重定向到 ssl 站点

java - 没有交互式弹出窗口的 Jcraft jsch

php - 在 if 语句中插入 HTML

php - 从 PHP 中的日期获取月份中的周数?

android - 有没有办法抑制 Android 设备上的低电量警告或消除警报弹出窗口?

java - Spring 批处理 : Compare Data Between Database

java - 将索引列添加到现有 Spark 的 DataFrame