java - 从我的 JSON 解析器获取空指针异常

标签 java php android json getjson

Error converting result java.lang.NullPointerException: lock == null Error parsing data org.json.JSONException: End of input at character 0 of

<小时/>

can anyone tell me if whether this work?? I have connected my laptop with my wifi and mobile also with that. both having the same ipv4 address, and in the android code i have mentioned that address. How will my mobile know to contact the laptop where the database is stored?

<小时/>

这是我的 Android 代码 JSON 解析器

 public JSONObject makeHttpRequest(String url, String method,List<NameValuePair> params) {
    try {
        if(method.equals("POST"))
        {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            Log.e("herehai"," "+is); 
            HttpPost httpPost = new HttpPost(url);
            Log.e("hereiam"," "+httpPost);
            httpPost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse httpResponse = httpClient.execute(httpPost);//<-----Error is here
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
            Log.e("here"," "+is);
        }
        else if(method.equals("GET"))
        {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

            Log.e("here1"," "+is);
        }


    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine())!=null)
        {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
        Log.e("errors",json);
    }
    catch (Exception e)  {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    //return json string
    return jObj;
}

有人可以告诉我为什么会抛出空指针异常吗?

最佳答案

试试这个

<?php
$con=mysqli_connect("localhost","root","") or  die(mysql_error());
mysqli_select_db($con,"something")or die("Unable to connect 1");
$response = array();
$response["success"] = 0;
$email = $_POST['email']; 
$passwd = $_POST['pass']; 
$query1 = mysqli_query($con,"SELECT pass FROM userinfo where email='$email'");

   $res= mysqli_fetch_assoc($query1);
        if($res)
        {
             if($passwd!=$res['pass'])
            {                    
                $response["success"]=1;
                print(json_encode($response));
            }
            else 
            {                    
                $response["success"]=0;
                print(json_encode($response));          
            }
        }
        else
        {
            $response["success"]=0;
            print(json_encode($res));   
        }
?>

关于java - 从我的 JSON 解析器获取空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35389033/

相关文章:

java - 如何在ipad上运行Servlet

c# - 如何使用 API 传输密码

android - 将 EditText 调整为字体大小

android - 在 React Native 上定位 android 30 sdk 时,Linking.canOpenURL 返回 false

java - 如何将android volley gson请求解析为对象列表/集合

Java游戏-将物体沿直线移动到另一点

php - file_get_contents() 在 Linux 中不起作用

android - Android中如何正确使用预加载数据库

java - Eclipse/Java 在 OpenSuse 12.2 中的 CPU 使用率总是超过 100%

php - 特殊字符未在 TEXTBOX 中正确显示