检查字符串是否相等会发出警告

时间:2016-03-16 20:14:06

标签: java android android-studio sdk

我在android studio中编写了一些代码,但在某些方面 它在代码中给我一些错误 我无法导入某些类并向我显示错误 我认为问题是sdk,我甚至改变了我的sdk 在build.gradle中,但它没有修复错误 请帮我解决一下:

 package com.example.delta.travel_json;


import android.util.Log;

import org.apache.http.HttpRequest;


import android.net.http.HttpResponseCache;
import android.provider.Settings;
import android.widget.Button;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

/**
 * Created by delta on 3/13/2016.
 */
public class JSONParser {

static InputStream is=null;
static JSONObject jObj=null;
static String json="";

//constructor

public  JSONParser(){

}

public JSONObject makeHttpRequest(String url,String method,List<NameValuePairs> params){

    try {
        if(method=="post"){
            DefaultHttpClient httpClient=new DefaultHttpClient();
            HttpPost httpPost=new HttpPost(url);
            httpPost.setEntity(new URLEncodedformEntity(params));

            HttpResponse httpResponse =new httpclient.execute(httpPost);
            HttpEntity httpEntity =httpResponse.getEntity();
            is=httpEntity.getContent();

        }else if(method=="GET"){
            DefaultHttpClient httpClient=new DefaultHttpClient();
            String paramString =URLEncoderUtils.format(params,"utf-8");
            url+="?"+paramString;
            HttpGet httpGet=new HttpGet(url);

            HttpResponse httpResponse=httpClient.execute(httpGet);
            HttpEntity httpEntity=httpResponse.getEntity();
            is=httpEntity.getContent();
        }
    }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();
        }catch(Exception e){
            Log.e("JSON Parser","Error paring data "+e.toString());
        }
    }return jObj;
}
}

和图片:

enter image description here

0 个答案:

没有答案