Android 从Google places api解析照片引用的JSON异常
我制作了一个json android应用程序,在列表视图中显示照片的引用,但它给了我一个错误 我的代码是\Android 从Google places api解析照片引用的JSON异常,android,json,google-places-api,Android,Json,Google Places Api,我制作了一个json android应用程序,在列表视图中显示照片的引用,但它给了我一个错误 我的代码是\ package com.example.jsonapp; import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity
package com.example.jsonapp;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
公共类MainActivity扩展了ListActivity{
//发出请求的url
私有静态字符串url=“/json?location=mylatandlong&radius=5000&types=restaurant&sensor=false&key=myownkey”
//JSON节点名称
私有静态最终字符串标记_RESULTS=“RESULTS”;
私有静态最终字符串标记_PHOTOS=“PHOTOS”;
私有静态最终字符串标记\u reference=“photo\u reference”;
JSONArray结果=null;
JSONArray photos=null;
上下文c;
//进度对话框
ProgressDialog;
ArrayList联系人列表;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
新的LaodPhotos().execute(标记参考);
//ListView lv=getListView();
}//创建时的结束
公共类LaodPhotos扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(MainActivity.this);
setMessage(“加载配置文件…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…arg0){
contactList=新的ArrayList();
JSONParser jParser=新的JSONParser();
JSONObject json=jParser.getJSONFromUrl(url);
试一试{
results=json.getJSONArray(TAG_results);
photos=json.getJSONArray(TAG_photos);
对于(int i=0;i您忘记在将活动上下文传递给SimpleAdapter之前使用活动上下文初始化c
上下文实例。因此,将活动上下文传递给适配器如下:
ListAdapter adapter = new SimpleAdapter(MainActivity.this,
contactList, R.layout.list_item,
new String[]{TAG_REFRENCE},
new int[]{R.id.photoRef});
MainActivity.this.setListAdapter(adapter);
而onPostExecute
方法已经在UI线程上运行,那么就不需要使用runOnUiThread
来更新UI元素表单onPostExecute只是一个提示-onPostExecute已经在UI线程上运行,没有理由在另一个调用中对其进行包装。很好,我已经完成了,但UI仍然没有显示任何内容,只有一个空白的白色屏幕
ListAdapter adapter = new SimpleAdapter(MainActivity.this,
contactList, R.layout.list_item,
new String[]{TAG_REFRENCE},
new int[]{R.id.photoRef});
MainActivity.this.setListAdapter(adapter);