0
應用程序運行時彈出以下錯誤,我有兩個類ListViewAdapter其他是JSONFunctions?什麼是錯誤,也許這是我的網址?我的API 77.105.36.203/api/v1/info的問題或問題是函數doInBackgoround JSONObject?值java.lang.String類型的<!DOCTYPE不能轉換爲JSONObject
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
ListViewAdapter adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String ID = "id";
static String IME = "ime";
static String ADRESA = "adresa";
static String SLIKA = "slika";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.listview_main, container, false);
new DownloadJSON().execute();
return rootView;
}
// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(getActivity());
// Set progressdialog title
mProgressDialog.setTitle("Android JSON Parse Tutorial");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions
.getJSONfromURL("http://77.105.36.203/api/v1/info");
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("objects");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put("id", jsonobject.getString("id"));
map.put("ime", jsonobject.getString("ime"));
map.put("adresa", jsonobject.getString("adresa"));
map.put("slika", jsonobject.getString("slika"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) getView().findViewById(R.layout.listview_item);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(getActivity(), arraylist);
// Set the adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
這是錯誤日誌。
07-10 16:15:59.605: E/log_tag(5389): Error parsing data [Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject]07-10 16:15:59.605: E/AndroidRuntime(5389): FATAL EXCEPTION: AsyncTask #2
顯示相同的錯誤 – elvis