Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.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
Java 我放在附加中的字符串是';我拿不出绳子_Java_Android_Android Intent_Android Activity - Fatal编程技术网

Java 我放在附加中的字符串是';我拿不出绳子

Java 我放在附加中的字符串是';我拿不出绳子,java,android,android-intent,android-activity,Java,Android,Android Intent,Android Activity,我正在开发一个android应用程序,用户可以向其他用户发送“推荐”。启动时,我运行以下方法,该方法查询远程数据库并检查新的引用: @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); String username = extras.getString(WeShouldActivity.ACCOUNT_NAME); HttpClient

我正在开发一个android应用程序,用户可以向其他用户发送“推荐”。启动时,我运行以下方法,该方法查询远程数据库并检查新的引用:

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    String username = extras.getString(WeShouldActivity.ACCOUNT_NAME);

    HttpClient httpclient = new DefaultHttpClient();

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("user_email", username));

    String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");

    HttpGet httpget = new HttpGet("http://23.23.237.174/check-referrals?"+paramString);

    JSONObject resp = new JSONObject();
    JSONArray data = new JSONArray();

    try {

        HttpResponse response = httpclient.execute(httpget);

        InputStream is = response.getEntity().getContent();


        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        int i=0;
        while(i != -1){
            i = is.read();
            baos.write(i);
        }



        byte[] buf = baos.toByteArray(); 
        //is.read(buf);

        Log.v("REFERRAL RESPONSE", new String(buf));

        resp = new JSONObject(new String(buf));

        data = resp.getJSONArray("referrals"); 


        Log.v("GETREFERRALSSERVICE", "Checking for new referrals");


    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        Log.v("GETREFERRALSSERVICE", e.getMessage());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.v("GETREFERRALSSERVICE", e.getMessage());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.v("GET REFFERAL SERVICE", "JSON EXCEPTION "+e.getMessage());
    }

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.restaurant;
    String tickerText = "New referrals!";
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, tickerText, when);

    Context context = getApplicationContext();
    CharSequence contentTitle = "New referrals!";

    Log.v("REFERRAL DATA", data.toString());

    if(data.length() >0){
        CharSequence contentText = "You have "+data.length()+" new referrals awaiting your approval.";
        Intent notificationIntent = new Intent(this, ApproveReferral.class);
        notificationIntent.putExtra("we.should.communication.data", data.toString());
        //Log.v("AFTER EXTRAS INSERT", notificationIntent.getStringExtra("data"));
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        notification.flags = notification.flags | Notification.FLAG_AUTO_CANCEL;
        nm.notify(ActivityKey.NEW_REFERRAL.ordinal(), notification);
    } 
}
而data.toString()看起来像:

05-28 12:53:10.874: V/REFERRAL DATA(13610): [{"data":"{\"website:0:1\":\"http:\\\/\\\/m.imdb.com\\\/title\\\/tt0848228\",\"name:0:0\":\"The Avengers\",\"comment:1:5\":\"2012\",\"rating:3:4\":\"5.0\",\"tags:1:6\":\"[{\\\"id\\\":2,\\\"color\\\":\\\"Red\\\",\\\"tag\\\":\\\"again\\\"}]\"}","item_name":"The Avengers","referred_by":"troyschuring@gmail.com"},{"data":"{\"website:0:1\":\"http:\\\/\\\/www.edgewaterhotel.com\\\/edgewater_dining.aspx\",\"name:0:0\":\"Six Seven\",\"comment:1:5\":\"\",\"phone number:2:2\":\"(206) 269-4575\",\"rating:3:4\":\"\",\"tags:1:6\":\"[]\",\"address:1:3\":\"{\\\"long\\\":-122.352644,\\\"address\\\":\\\"2411 Alaskan Way, Seattle, WA, United States\\\",\\\"lat\\\":47.612579}\"}","item_name":"Six Seven","referred_by":"cc.emeraldeyes@gmail.com"},{"data":"{\"website:0:1\":\"http:\\\/\\\/www.paseoseattle.com\\\/\",\"name:0:0\":\"Paseo\",\"comment:1:5\":\"\",\"phone number:2:2\":\"(206) 545-7440\",\"rating:3:4\":\"5.0\",\"tags:1:6\":\"[{\\\"id\\\":1,\\\"color\\\":\\\"Purple\\\",\\\"tag\\\":\\\"Colin\\\"}]\",\"address:1:3\":\"{\\\"long\\\":-122.3501502,\\\"address\\\":\\\"4225 Fremont Avenue North, Seattle, WA, United States\\\",\\\"lat\\\":47.6586176}\"}","item_name":"Paseo","referred_by":"cc.emeraldeyes@gmail.com"}]
看,共有3项

然后在ApproverFerral的开头:

05-28 12:53:13.877: V/DATA EXTRA(13610): [{"data":"{\"website:0:1\":\"http:\\\/\\\/m.imdb.com\\\/title\\\/tt0848228\",\"name:0:0\":\"The Avengers\",\"comment:1:5\":\"2012\",\"rating:3:4\":\"5.0\",\"tags:1:6\":\"[{\\\"id\\\":2,\\\"color\\\":\\\"Red\\\",\\\"tag\\\":\\\"again\\\"}]\"}","item_name":"The Avengers","referred_by":"troyschuring@gmail.com"},{"data":"{\"website:0:1\":\"http:\\\/\\\/www.edgewaterhotel.com\\\/edgewater_dining.aspx\",\"name:0:0\":\"Six Seven\",\"comment:1:5\":\"\",\"phone number:2:2\":\"(206) 269-4575\",\"rating:3:4\":\"\",\"tags:1:6\":\"[]\",\"address:1:3\":\"{\\\"long\\\":-122.352644,\\\"address\\\":\\\"2411 Alaskan Way, Seattle, WA, United States\\\",\\\"lat\\\":47.612579}\"}","item_name":"Six Seven","referred_by":"cc.emeraldeyes@gmail.com"}]
现在只有两个

我能想到的唯一一件事是ApproverFerral,出于某种原因,是“缓存”(我把它放在引号里,因为我不熟悉android,也不确定这个词有多适用)它的额外功能,并且没有使用更新的额外功能


如何修复此问题?

事实证明,这是的一个副本


添加标志\u UPDATE\u CURRENT似乎解决了问题。

您是否尝试发送2个值而不是3个值,以检查是否被剪切为1或4,并且收到的字符串包含3个元素,或者是一个不同的字符串,然后检查您收到的字符串是否与您发布的字符串完全相同?我在几个不同的变体中遇到过这个问题-2,我只得到1,4,我只得到2,他们唯一的共同点是,在某一点上,他们是正确的——就像更新没有完全做到一样。很可能是重复的,显然是。我得知道该找什么。我有可怜的谷歌foo。
05-28 12:53:10.874: V/REFERRAL DATA(13610): [{"data":"{\"website:0:1\":\"http:\\\/\\\/m.imdb.com\\\/title\\\/tt0848228\",\"name:0:0\":\"The Avengers\",\"comment:1:5\":\"2012\",\"rating:3:4\":\"5.0\",\"tags:1:6\":\"[{\\\"id\\\":2,\\\"color\\\":\\\"Red\\\",\\\"tag\\\":\\\"again\\\"}]\"}","item_name":"The Avengers","referred_by":"troyschuring@gmail.com"},{"data":"{\"website:0:1\":\"http:\\\/\\\/www.edgewaterhotel.com\\\/edgewater_dining.aspx\",\"name:0:0\":\"Six Seven\",\"comment:1:5\":\"\",\"phone number:2:2\":\"(206) 269-4575\",\"rating:3:4\":\"\",\"tags:1:6\":\"[]\",\"address:1:3\":\"{\\\"long\\\":-122.352644,\\\"address\\\":\\\"2411 Alaskan Way, Seattle, WA, United States\\\",\\\"lat\\\":47.612579}\"}","item_name":"Six Seven","referred_by":"cc.emeraldeyes@gmail.com"},{"data":"{\"website:0:1\":\"http:\\\/\\\/www.paseoseattle.com\\\/\",\"name:0:0\":\"Paseo\",\"comment:1:5\":\"\",\"phone number:2:2\":\"(206) 545-7440\",\"rating:3:4\":\"5.0\",\"tags:1:6\":\"[{\\\"id\\\":1,\\\"color\\\":\\\"Purple\\\",\\\"tag\\\":\\\"Colin\\\"}]\",\"address:1:3\":\"{\\\"long\\\":-122.3501502,\\\"address\\\":\\\"4225 Fremont Avenue North, Seattle, WA, United States\\\",\\\"lat\\\":47.6586176}\"}","item_name":"Paseo","referred_by":"cc.emeraldeyes@gmail.com"}]
05-28 12:53:13.877: V/DATA EXTRA(13610): [{"data":"{\"website:0:1\":\"http:\\\/\\\/m.imdb.com\\\/title\\\/tt0848228\",\"name:0:0\":\"The Avengers\",\"comment:1:5\":\"2012\",\"rating:3:4\":\"5.0\",\"tags:1:6\":\"[{\\\"id\\\":2,\\\"color\\\":\\\"Red\\\",\\\"tag\\\":\\\"again\\\"}]\"}","item_name":"The Avengers","referred_by":"troyschuring@gmail.com"},{"data":"{\"website:0:1\":\"http:\\\/\\\/www.edgewaterhotel.com\\\/edgewater_dining.aspx\",\"name:0:0\":\"Six Seven\",\"comment:1:5\":\"\",\"phone number:2:2\":\"(206) 269-4575\",\"rating:3:4\":\"\",\"tags:1:6\":\"[]\",\"address:1:3\":\"{\\\"long\\\":-122.352644,\\\"address\\\":\\\"2411 Alaskan Way, Seattle, WA, United States\\\",\\\"lat\\\":47.612579}\"}","item_name":"Six Seven","referred_by":"cc.emeraldeyes@gmail.com"}]