对于Android中的String类型,方法getString(String)未定义

时间:2015-05-19 02:13:26

标签: java android android-activity parse-platform

我正在尝试使用Parse.com推送url并且我添加了一个代码,其中get String显示错误。任何人都可以帮帮我!

请帮帮我!得到错误

  

对于String **

类型,未定义方法getString(String)
    package com.example.pushnotificationdemo;



import org.json.JSONObject;

import com.example.pushnotificationdemo.R;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;



public class MainActivity extends ActionBarActivity {

    WebView webframe;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        String jsonData = extras.getString("com.parse.Data");
        JSONObject json = new JSONObject(jsonData);
        String pushStore = json.getString("data");
        if(pushStore!=null) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pushStore.getString("url")));
          startActivity(browserIntent);
        } 

        setContentView(R.layout.activity_main);

        ParseAnalytics.trackAppOpenedInBackground(getIntent());

        PushService.setDefaultPushCallback(this, MainActivity.class);
        ParseInstallation.getCurrentInstallation().saveInBackground();



        /** Cerco l'elemento in /res/layout/main.xml */
        webframe = (WebView) findViewById(R.id.webview);

        /** Javascript abilitato (ma non flash) */
        webframe.getSettings().setJavaScriptEnabled(true);



        /** Simulo il webbrowser chrome di android*/
        webframe.setWebChromeClient(new WebChromeClient()); 
        webframe.setWebViewClient(new WebViewClient()); 

        /** Assegno l'url di apertura del webframe */
        webframe.loadUrl("http://www.dlybugs.com");






    }
}

1 个答案:

答案 0 :(得分:0)

您收到此代码中的错误:

pushStore

因为StringJSONObject。您可以拨打getStringString pushStore = json.getString("data.url"); if(pushStore!=null) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pushStore)); startActivity(browserIntent); } 。你可能想要这个代码:

app.use(require('prerender-node').set('prerenderToken', 'YOUR_TOKEN'));