Android 正在将jsonAsync代码放入单独的类。。。安卓

Android 正在将jsonAsync代码放入单独的类。。。安卓,android,json,class,asynchronous,Android,Json,Class,Asynchronous,我试图使我的代码如下所示: 这就是我使用Async类调用和发送的方式,看起来不错。 如果我把所有的代码都放在MainActivity中,它就可以工作了,但是我似乎无法通过外部类让这些代码工作 我的主要活动代码:(重要的部分) 公共类MainActivity扩展了FragmentActivity实现ActionBar.OnNavigationListener{ 私有静态最终字符串url=”http://www.somesite.com/JSON.php"; 公共邮政; 公共列表视图列表视图; 公共

我试图使我的代码如下所示: 这就是我使用Async类调用和发送的方式,看起来不错。 如果我把所有的代码都放在MainActivity中,它就可以工作了,但是我似乎无法通过外部类让这些代码工作

我的主要活动代码:(重要的部分)

公共类MainActivity扩展了FragmentActivity实现ActionBar.OnNavigationListener{
私有静态最终字符串url=”http://www.somesite.com/JSON.php";
公共邮政;
公共列表视图列表视图;
公共字符串jsonResult;
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
initializeDialog();
setContentView(R.layout.activity_main);
listView=(listView)findViewById(R.id.listView1);
accessWebService();
}
私有void accessWebService(){
JsonReadTask jsonTask=新的JsonReadTask();
execute(新字符串[]{url,post},this);
}
private void initializeDialog(){
dialog=ProgressDialog.show(MainActivity.this,“,”LoadingData.Wait…”,true);
dialog.show();
}   
公开作废清单出票人(){
List galleryList=新的ArrayList();
试一试{
JSONObject jsonResponse=新的JSONObject(jsonResult);
JSONArray jsonMainNode=jsonResponse.optJSONArray(“库”);
for(int i=0;i
但是在异步类上: ^我会遇到这样的错误:“java.lang.String[]不能转换为java.lang.String” 发生这种情况的地方:“String serviceUrl=(String)params[0];”就是我遇到问题的地方。。? 至少在“doInBackground”中:“执行doInBackground()时出错”

我的异步类代码:(重要的部分)

公共类JsonReadTask扩展了AsyncTask{
主要活动:实用性;
@凌驾
公共字符串doInBackground(对象…参数){
callerActivity=(MainActivity)参数[1];
HttpClient HttpClient=新的DefaultHttpClient();
String theurl=(String)参数[0];//urlJSON
HttpPost HttpPost=新的HttpPost(URL);
试一试{
List nameValuePairs=新的ArrayList(2);
字符串post=(字符串)参数[1];//表名
添加(新的基本名称对(“getgallery”、“thepost”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
CallePractivity.jsonResult=inputStreamToString(response.getEntity().getContent()).toString();
}
捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
返回null;
}
应用程序在启动时崩溃,导致对话框崩溃。 提前感谢您的帮助

编辑
我的日志猫:

在崩溃日志中有两行重要的代码:

10-13 11:49:43.881: E/AndroidRuntime(7289): Caused by: java.lang.ClassCastException: java.lang.String[] cannot be cast to java.lang.String
10-13 11:49:43.881: E/AndroidRuntime(7289):     at com.example.providenceartapp.JsonReadTask.doInBackground(JsonReadTask.java:31)
当您试图将字符串数组用作单个字符串时,它看起来好像在这里

String theurl = (String) params[0]; //urlJSON;

params[0]
是一个数组。

好的,这是我的日志cat:jsonTask.execute(新字符串[]{url,post},this);<这是我将字符串发送到异步类的方式,params[]只是从字符串数组中获取一个字符串。有没有办法转换它以便工作?或者绕过它?您正在传递一个字符串数组和一个活动,所以
params[0]
是一个字符串数组。如果你想获取url,你必须执行
string theurl=params[0][0]
当我这样做时,我会得到:“表达式的类型必须是数组类型,但它解析为对象”,这是因为params对象是一个对象数组。如果执行
string[]parameters=(string[])params[0],你会得到什么
然后
String theurl=parameters[0]
?很好!这修复了错误。:)还有一件事,当我尝试对我的表字符串执行相同操作时…我得到了以下错误:(包含代码)
10-13 11:49:43.881: E/AndroidRuntime(7289): Caused by: java.lang.ClassCastException: java.lang.String[] cannot be cast to java.lang.String
10-13 11:49:43.881: E/AndroidRuntime(7289):     at com.example.providenceartapp.JsonReadTask.doInBackground(JsonReadTask.java:31)
String theurl = (String) params[0]; //urlJSON;