내 코드를 다음과 같이 만들려고했습니다. https://github.com/jbeerdev/BrightHubCode/blob/master/src/com/bright/hub/background/WebServiceBackgroundActivity.java 이것은 내가 비동기 클래스로 호출하고 보내는 방법입니다. MainActivity에 모든 코드를 입력하면 작동하지만 외부 클래스를 통해이 코드를 가져올 수 없습니다. "java.lang.String의가 [] 자바로 캐스팅 할 수 없습니다 https://github.com/jbeerdev/BrightHubCode/blob/master/src/com/bright/hub/background/WebServiceAsyncTask.java 가^나는 이러한 종류의 오류를 얻을 :jsonAsync 코드를 별도의 클래스에 넣는 중 ...
내 MainActivity 코드 :
public class MainActivity extends FragmentActivity implements ActionBar.OnNavigationListener {
private static final String url = "http://www.somesite.com/JSON.php";
public String post;
public ListView listView;
public String jsonResult;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initializeDialog();
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView1);
accessWebService();
}
private void accessWebService() {
JsonReadTask jsonTask = new JsonReadTask();
jsonTask.execute(new String[] { url, post },this);
}
private void initializeDialog() {
dialog = ProgressDialog.show(MainActivity.this, "", "LoadingData. Wait...", true);
dialog.show();
}
public void ListDrawer() {
List<Map<String, String>> galleryList = new ArrayList<Map<String, String>>();
try {
JSONObject jsonResponse = new JSONObject(jsonResult);
JSONArray jsonMainNode = jsonResponse.optJSONArray("galleries");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String loc = jsonChildNode.optString("loc");
String foto = jsonChildNode.optString("foto");
String outPut = "http://www.somesite.com/images/" + loc + foto;
galleryList.add(createGallery("galleries", outPut));
}
} catch (JSONException e) {
//Toast.makeText(getApplicationContext(), "Error" + e.toString(),
//Toast.LENGTH_LONG).show();
}
}
그러나 비동기 클래스 (문제 부분) .lang.String " 이렇게되는 곳 :"String serviceUrl = (String) params [0]; " 내가 문제가있는 곳이야 ..? (중요 부분) 부팅
public class JsonReadTask extends AsyncTask<Object, Void, String> {
MainActivity callerActivity;
@Override
public String doInBackground(Object... params) {
callerActivity = (MainActivity) params[1];
HttpClient httpclient = new DefaultHttpClient();
String theurl = (String) params[0]; //urlJSON
HttpPost httppost = new HttpPost(theurl);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
String thepost = (String) params[1]; //tablename
nameValuePairs.add(new BasicNameValuePair("getgallery", "thepost"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
callerActivity.jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
애플 리케이션 충돌이주는 대화 그것을 :
내 비동기 클래스 코드 "doInBackground()를 실행하는 동안 오류가 발생" 그것은 적어도 "doInBackground"에의 추락했다. 도움에 미리 감사드립니다!
편집 내 로그 캣 : http://pastebin.com/XZaNZTTg
충돌 로그 게시! – Nerd
좋아, 내 로그 고양이입니다 : http://pastebin.com/XZaNZTTg – Arndroid