[英]Uri.parse give the null value
我已經成功地從另一個數據庫中獲取了數據,並且可以在TextView上打印它。 但是,當我嘗試像下面這樣將數據傳遞到Uri.pase()
,它為我提供了null。
public void gotosite(View v) {
s = responseTextView.getText().toString();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"+s+""));
startActivity(i);
}
這個方法給TextView打印我期望的數據。 我想在Uri.parse()設置數據
public void setTextToTextView(JSONArray jsonArray) {
String s = "";
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject json = null;
try {
json = jsonArray.getJSONObject(i);
s = s + json.getString("adUrl");
} catch (JSONException e) {
e.printStackTrace();
}
}
this.responseTextView.setText(s);
}
您需要全局聲明String,以用於不同的方法。 確保首先運行setTextToTextView
方法,然后再將gotosite()
方法作為String s=""
。
String s; // declare this globally
public void setTextToTextView(JSONArray jsonArray) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject json = null;
try {
json = jsonArray.getJSONObject(i);
s = s + json.getString("adUrl");
} catch (JSONException e) {
e.printStackTrace();
}
}
this.responseTextView.setText(s);
}
public void gotosite(View v) {
s=responseTextView.getText().toString(); // either use this or you can now use string s directly
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"+s+""));
startActivity(i);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.