Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 添加提示时java.io.FileNotFoundException_Android_Foursquare - Fatal编程技术网

Android 添加提示时java.io.FileNotFoundException

Android 添加提示时java.io.FileNotFoundException,android,foursquare,Android,Foursquare,使用/tips/addapi时出现java.io.FileNotFoundException。以下是我的源代码: public void addTip(final String venueId, final String text) { new Thread() { @Override public void run() { try { URL url = new URL(FOURSQUAR

使用
/tips/add
api时出现
java.io.FileNotFoundException
。以下是我的源代码:

    public void addTip(final String venueId, final String text) {
    new Thread() {
        @Override 
        public void run() {
            try {
                URL url = new URL(FOURSQUARE_API
                        + "/tips/add"
                        + "?venueId=" + venueId
                        + "&text=" + text
                        + "&oauth_token=" + mAccessToken
                        + "&v=" + mVersion);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                Log.d(TAG, "opening url " + url);
                urlConnection.setRequestMethod("POST");
                urlConnection.setDoInput(true);
                urlConnection.setDoOutput(true);

                urlConnection.connect();

                try {
                JSONObject response = getResponse(urlConnection);
                String tipId = response.getString("id");
                String text  = response.getString("text");
                Log.d(TAG, "tipId:" + tipId + "; " + "text:" + text);
                } catch (Exception e) {
                    String response = streamToString(urlConnection.getErrorStream());
                    Log.d(TAG, response);
                    throw e;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}
    private JSONObject getResponse(HttpURLConnection urlConnection) throws Exception {
    String response = streamToString(urlConnection.getInputStream());
    JSONObject jsonObject = (JSONObject) new JSONTokener(response).nextValue();
    JSONObject resp = jsonObject.getJSONObject("response");
    return resp;
}

private  String streamToString(InputStream is) throws IOException {
    String str  = "";

    if (is != null) {
        StringBuilder sb = new StringBuilder();
        String line;

        try {
            BufferedReader reader   = new BufferedReader(new InputStreamReader(is));

            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }

            reader.close();
        } finally {
            is.close();
        }

        str = sb.toString();
    }

    return str;
}
以及错误信息:

     12-24 21:31:18.758: W/System.err(2356): java.io.FileNotFoundException: https://api.foursquare.com/v2/tips/add?venueId=4ef2cdd0b634355dee1f1794&text=classroom for sei students&oauth_token=CONS3IBOUEH2YTBA3IMNI3YH4CWSUKQ500QSOXJZQ23LXBH1&v=20111224
     12-24 21:31:18.768: W/System.err(2356):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
     12-24 21:31:18.768: W/System.err(2356):    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:258)
     12-24 21:31:18.768: W/System.err(2356):    at com.ecnu.sei.manuzhang.study.FoursquareAPI.getResponse(FoursquareAPI.java:339)
     12-24 21:31:18.768: W/System.err(2356):    at com.ecnu.sei.manuzhang.study.FoursquareAPI.access$7(FoursquareAPI.java:338)
     12-24 21:31:18.768: W/System.err(2356):    at com.ecnu.sei.manuzhang.study.FoursquareAPI$2.run(FoursquareAPI.java:133)
奇怪的是,在捕捉到异常后,我从
getErrorStream()
中什么也没有得到。
有什么想法吗?您可以找到文档

您需要对
文本
位进行编码。试试这个:

+ "&text=" + URLEncoder.encode(text,"UTF-8");

是的。。容易忽视。。而愚蠢的错误信息一点帮助也没有:)