I'm sorry for the noob question but I'm just stumped as to how to approach this issue...
1: I am receiving this error when testing on usb attached phone but not when on AVD when search is executed.
Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
2: While running in AVD, the first JSON search is successful but once backed out and attempted to access a new search the result is empty. Below is the JSON list activity that is instantiated after the search:
package com.example.georgiahistoricalmarkers;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class MainListActivity extends ListActivity {
// url to make request
private static String url = "http://www.georgiaplanning.com/DCAMarkerService/dcamarkerservice.markerservice.svc/rest/Locations?SearchText=";
// JSON Node names
private static final String TAG_MARKERSINRANGE = "GetAllMarkersInRangeResult";
private static final String TAG_DCAID = "DCA_ID";
private static final String TAG_MARKERTITLE = "MarkerTitle";
private static final String TAG_MARKERLATITUDE = "MarkerLatitude";
private static final String TAG_MARKERLONGITUDE = "MarkerLongitude";
// contacts JSONArray
JSONArray markersInRange = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String value = null;
Bundle extras = getIntent().getExtras();
if(extras != null){
value = extras.getString("markerSearch");
}
url = (url+value);
// Hashmap for ListView
ArrayList<HashMap<String, String>> markerList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
markersInRange = json.getJSONArray(TAG_MARKERSINRANGE);
// looping through All Contacts
for(int i = 0; i < markersInRange.length(); i++){
JSONObject c = markersInRange.getJSONObject(i);
// Storing each json item in variable
int dcaid = c.getInt(TAG_DCAID);
String markertitle = c.getString(TAG_MARKERTITLE);
double markerlongitude = c.getDouble(TAG_MARKERLATITUDE);
double markerlatitude = c.getDouble(TAG_MARKERLONGITUDE);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_DCAID, Integer.toString(dcaid));
map.put(TAG_MARKERTITLE, markertitle);
map.put(TAG_MARKERLONGITUDE, Double.toString(markerlongitude));
map.put(TAG_MARKERLONGITUDE, Double.toString(markerlatitude));
// adding HashList to ArrayList
markerList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, markerList,
R.layout.list_item,
new String[] { TAG_MARKERTITLE, TAG_DCAID }, new int[] {
R.id.title, R.id.dcaid });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String passId = ((TextView) view.findViewById(R.id.dcaid)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleItemActivity.class);
in.putExtra(TAG_DCAID, passId);
startActivity(in);
}
});
}
}
Below is my Manifest if that might help understand the issue:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.georgiahistoricalmarkers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.georgiahistoricalmarkers.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainListActivity"
android:label="MainListActivity" >
</activity>
<activity
android:name=".SingleItemActivity"
android:label="SingleItemActivity" >
</activity>
</application>