これは私の検索アクティビティです。以下のコードを使用しています。ブラウザーで SearchUrl をヒットすると、正しい応答が得られますが、このコードを使用して解析中にエラーが発生します。なぜこれが起こるのかわかりませんか?
public class SearchListActivity extends Activity {
ListView SearchResults;
private String SearchUrl = "http://www.adultretailfinder.com.au/api/search?transport=get&";
AdultRetailFinderUtils util;
ArrayList<AdultRetailFinderDTO> SearchArrayList;
ListAdapter adapter;
JSONObject json;
Bundle myBundle;
private JSONParser jsonParser;
String SearchKeyword, type;
MyCustomAdapter myAdapter;
JSONArray searchArray = null;
ProgressDialog dialog;
Boolean searchFlag = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.search_list_layout);
initDisplay();
}
class MyCustomAdapter extends BaseAdapter {
public int getCount() {
return SearchArrayList.size();
}
public String getItem(int position) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.searchrow_layout, parent, false);
TextView BusinessText = (TextView) row.findViewById(R.id.txt);
BusinessText.setText(SearchArrayList.get(position)
.getBusinessName());
return (row);
}
}
private void initDisplay() {
myBundle = new Bundle();
myBundle = getIntent().getExtras();
SearchResults = (ListView) findViewById(R.id.search_lv);
dialog = new ProgressDialog(SearchListActivity.this);
jsonParser = new JSONParser();
SearchArrayList = new ArrayList<AdultRetailFinderDTO>();
util = new AdultRetailFinderUtils(SearchListActivity.this);
SearchKeyword = myBundle.getString("SEARCHKEYWORD");
type = myBundle.getString("TYPE");
Log.v("SEARCHKEYWORD::", SearchKeyword);
Log.v("TYPE::", type);
myAdapter = new MyCustomAdapter();
if (jsonParser.isNetworkAvailable(SearchListActivity.this)) {
new BGTaskForSearch().execute();
} else {
Toast.makeText(SearchListActivity.this,
getResources().getString(R.string.network_not_available),
Toast.LENGTH_LONG).show();
}
}
private class BGTaskForSearch extends
AsyncTask<String, Void, ArrayList<AdultRetailFinderDTO>> {
protected void onPreExecute() {
dialog.setMessage("Loading...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected ArrayList<AdultRetailFinderDTO> doInBackground(String... args) {
// String urlstr= searchURL+selectedData+"Status=1&Prov_ID=19";
List<NameValuePair> params = new LinkedList<NameValuePair>();
params.add(new BasicNameValuePair("keywords", SearchKeyword));
params.add(new BasicNameValuePair("filter", "shops"));
params.add(new BasicNameValuePair("type", type));
String paramString = URLEncodedUtils.format(params, "utf-8");
String newUrl = SearchUrl + paramString;
Log.v("urlstr", newUrl);
JSONObject json = jsonParser.getJSONFromUrl(newUrl);
SearchArrayList = util.getJsonParsedResp(json);
// TODO Auto-generated method stub
if (SearchArrayList != null) {
return SearchArrayList;
} else {
return null;
}
}
protected void onPostExecute(ArrayList<AdultRetailFinderDTO> list) {
dialog.dismiss();
if (list != null) {
SearchResults.setAdapter(myAdapter);
} else
Toast.makeText(SearchListActivity.this, "no records are found",
Toast.LENGTH_LONG).show();
}
}
}
私が得ているこのタイプのエラー:
01-29 17:24:06.027: E/Trace(1775): error opening trace file: No such file or directory (2)
01-29 17:24:06.577: D/dalvikvm(1775): GC_FOR_ALLOC freed 72K, 3% free 8056K/8259K, paused 41ms, total 42ms
01-29 17:24:06.597: I/dalvikvm-heap(1775): Grow heap (frag case) to 9.380MB for 1536016-byte allocation
01-29 17:24:06.707: D/dalvikvm(1775): GC_CONCURRENT freed 1K, 3% free 9555K/9799K, paused 72ms+4ms, total 116ms
01-29 17:24:06.797: D/dalvikvm(1775): GC_FOR_ALLOC freed 4K, 3% free 9725K/9991K, paused 38ms, total 38ms
01-29 17:24:06.807: I/dalvikvm-heap(1775): Grow heap (frag case) to 10.455MB for 953364-byte allocation
01-29 17:24:06.927: D/dalvikvm(1775): GC_CONCURRENT freed <1K, 3% free 10656K/10951K, paused 74ms+5ms, total 116ms
01-29 17:24:06.927: D/dalvikvm(1775): WAIT_FOR_CONCURRENT_GC blocked 7ms
01-29 17:24:07.277: I/Choreographer(1775): Skipped 53 frames! The application may be doing too much work on its main thread.
01-29 17:24:07.397: D/gralloc_goldfish(1775): Emulator without GPU emulation detected.
01-29 17:24:07.637: I/Choreographer(1775): Skipped 65 frames! The application may be doing too much work on its main thread.
01-29 17:24:13.086: V/SEARCHKEYWORD::(1775): adult
01-29 17:24:13.086: V/TYPE::(1775): business
01-29 17:24:13.246: V/SEARCHKEYWORD::(1775): adult
01-29 17:24:13.256: V/TYPE::(1775): business
01-29 17:24:13.286: V/urlstr(1775): http://www.adultretailfinder.com.au/api/search?transport=get&keywords=adult&filter=shops&type=business
01-29 17:24:17.836: D/dalvikvm(1775): GC_CONCURRENT freed 250K, 4% free 11229K/11591K, paused 71ms+74ms, total 174ms
01-29 17:24:18.186: V/JSON(1775): <!DOCTYPE html>n<html>n<head>nn <!--<meta name="viewport" content="width=device-width; target-densitydpi=device-dpi;">--><!--<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0"/>-->n <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />nn <meta name="HandheldFriendly" content="true" />n <!--<meta http-equiv="cleartype" content="on">-->n <meta name="format-detection" content="telephone=no" />n <meta name="format-detection" content="address=no" />n <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />nn <title>Find Adult Shops, Online Shops, Party Plans and Adult Entertainment</title>n <meta name="description" content="Adult Retail Finder makes it easy to locate adult shops, online stores, adult party plan and adult entertanment across Australia and New Zealand " />n <meta name="keywords" content="Adult Shop, Adult Party Plan, Online Adult Shop, Adult Entertainment, Adult Shop Directory, Adult Directory, Adult Retail Finder " />n <link href="/external.css" rel="stylesheet" type="text/css" />n <link href="/style.css" rel="stylesheet" type="text/css" />nn <script type="text/javascript">nn var _gaq = _gaq || [];n _gaq.push(['_setAccount', 'UA-19656663-32']);n _gaq.push(['_setDomainName', 'adultretailfinder.com.au']);n _gaq.push(['_trackPageview']);nn (function () {n var ga = document.createElement('script');n ga.type = 'text/javascript';n ga.async = true;n ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';n var s = document.getElementsByTagName('script')[0];n s.parentNode.insertBefore(ga, s);n })();nn </script>nn <style type="text/css">n #AutoCompleten {n background:#FFFFFF;n color:#000000;n border:solid 1px #CCCCCC;n text-align:left;n position:absolute;n z-index:10000;n font-size:12px;n padding:2px 2px;n }nn #ExitAutoCompleten {n width:16px;n height:16px;n position:absolute;n z-index:auto;n cursor:pointer;n }nn .AutoItem1 a:linkn {n font-size:12px;n color:#000000;n text-decoration:none;n }n .AutoItem1 a:hovern {n font-size:12px;n color:#000000;n text-decoration:none;n }n .AutoItem1 a:visitedn {n font-size:12px;n color:#000000;n text-decoration:none;n }n .AutoItem1 a:activen {n font-size:12px;n color:#000000;n text-decoration:none;n }n .AutoItem1n {n font-size:12px;n background:#f7f7f7;n cursor:pointer;n }nn .AutoItem2 a:linkn {n font-size:12px;n color:#000000;n text-decoration:none;n }n .AutoItem2 a:hovern {n font-size:12px;n color:#000000;n text-decoration:none;n }n .AutoItem2 a:visitedn {n font-size:12px;n color:#000000;n text-decoration:none;n }nn .AutoItem2 a:activen {n font-size:12px;n color:#000000;n text-decoration:none;n }n .AutoItem2n {n font-size:12px;n background:#FFFFFF;n cursor:pointer;n }nn .AutoItemOvern {n font-size:12px;n background:#ffe8f2;n cursor:pointer;n }n</style>nn<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>nn<script type="text/javascript">nn/*Bob Monteverde*/nString.prototype.width = function(font) {n var f = font || '12px arial',n o = $('<div>' + this + '</div>')n .css({'position': 'absolute', 'float': 'left', 'visibility': 'hidden', 'font': f})n .appendTo($('body')),n w = o.width();nn o.remove();nn return w;n};nn$(document).ready(function()n{ n $("#AutoComplete").hide();n $("#ExitAutoComplete").h
01-29 17:24:18.186: V/JSON Parser(1775): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
01-29 17:24:18.196: W/dalvikvm(1775): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
01-29 17:24:18.206: E/AndroidRuntime(1775): FATAL EXCEPTION: AsyncTask #1
01-29 17:24:18.206: E/AndroidRuntime(1775): java.lang.RuntimeException: An error occured while executing doInBackground()
01-29 17:24:18.206: E/AndroidRuntime(1775): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-29 17:24:18.206: E/AndroidRuntime(1775): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.lang.Thread.run(Thread.java:856)
01-29 17:24:18.206: E/AndroidRuntime(1775): Caused by: java.lang.NullPointerException
01-29 17:24:18.206: E/AndroidRuntime(1775): at com.adultretailfinder.AdultRetailFinderUtils.getJsonParsedResp(AdultRetailFinderUtils.java:24)
01-29 17:24:18.206: E/AndroidRuntime(1775): at com.adultretailfinder.SearchListActivity$BGTaskForSearch.doInBackground(SearchListActivity.java:128)
01-29 17:24:18.206: E/AndroidRuntime(1775): at com.adultretailfinder.SearchListActivity$BGTaskForSearch.doInBackground(SearchListActivity.java:1)
01-29 17:24:18.206: E/AndroidRuntime(1775): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-29 17:24:18.206: E/AndroidRuntime(1775): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-29 17:24:18.206: E/AndroidRuntime(1775): ... 5 more
01-29 17:29:18.344: I/Process(1775): Sending signal. PID: 1775 SIG: 9
ユーティリティ クラス
public class AdultRetailFinderUtils {
private Context context;
public AdultRetailFinderUtils(Context mcontext) {
context = mcontext;
}
public ArrayList<AdultRetailFinderDTO> getJsonParsedResp(JSONObject jsonObj) {
ArrayList<AdultRetailFinderDTO> searchArrayList = new ArrayList<AdultRetailFinderDTO>();
try {
JSONArray jsArray = jsonObj.getJSONArray("data");
if (jsArray.length() > 0) {
for (int i = 0; i < jsArray.length(); i++) {
AdultRetailFinderDTO dto = new AdultRetailFinderDTO();
JSONObject jsonObject = jsArray.getJSONObject(i);
Integer id= jsonObject.getInt("id") ;
String businessName = jsonObject.getString("business");
String type = jsonObject.getString("type");
dto.setId(id);
dto.setBusinessName(businessName);
dto.setType(type);
searchArrayList.add(dto);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (searchArrayList.size() > 0) {
return searchArrayList;
} else {
return null;
}
}
}
なぜ?
前もって感謝します!