这是我的代码:
protected List<MovieModel> doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String finalJson = buffer.toString();
JSONObject parentObject = new JSONObject(finalJson);
JSONArray parentArray = parentObject.getJSONArray("movies");
List<MovieModel> movieModelList = new ArrayList<>();
Gson gson = new Gson();
for (int i = 0; i < parentArray.length(); i++) {
JSONObject finalObject = parentArray.getJSONObject(i);
/**
* below single line of code from Gson saves you from writing the json parsing yourself
* which is commented below
*/
MovieModel movieModel = gson.fromJson(finalObject.toString(), MovieModel.class); // a single line json parsing using Gson
movieModel.setMovie(finalObject.getString("movie"));
movieModel.setYear(finalObject.getInt("year"));
movieModel.setRating((float) finalObject.getDouble("rating"));
movieModel.setDirector(finalObject.getString("director"));
movieModel.setDuration(finalObject.getString("duration"));
movieModel.setTagline(finalObject.getString("tagline"));
movieModel.setImage(finalObject.getString("image"));
movieModel.setStory(finalObject.getString("story"));
List<MovieModel.Cast> castList = new ArrayList<>();
for (int j = 0; j < finalObject.getJSONArray("cast").length(); j++) {
MovieModel.Cast cast = new MovieModel.Cast();
cast.setName(finalObject.getJSONArray("cast").getJSONObject(j).getString("name"));
castList.add(cast);
}
movieModel.setCastList(castList);
// adding the final object in the list
movieModelList.add(movieModel);
}
return movieModelList;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
enter code here
您忘记将INTERNET权限添加到您的清单中,在此
<uses-permission android:name="android.permission.INTERNET" />
java.lang.RuntimeException:执行doInBackground()E/Android runtime(695)时出错:at Android . OS . async task $ 3 . done(async task . Java:200)E/Android runtime(695):at Java . util . concurrent . future task $
我做了一个应用程序登录,一切都是正常的昨天,但今天android工作室给了我这个错误 {08-03 14:29:07.894 137 03-14015/Complete.Lyne.MyApplication E/AndroidRuntime:致命异常:AsyncTask#1进程:Complete.Lyne.MyApplication,PID:13703 java.lang.RuntimeExcep
我在android设备上构建代码时出错了。这是错误报告 05-17 09:47:16.035 17982-18134/com . example . ckw . mapku E/Android runtime:致命异常:async task # 1 05-17 09:47:16.035 17982-18134/com . example . mapku E/Android runtime:Proc
Google play商店仅在小米设备上显示崩溃(我无法复制)。请在下面找到崩溃日志。我也曾试图在小米设备上重现这次崩溃,但无法重现。 orker.run运行时异常:在xecutor.java:588AsyncTask$java.lang.(AsyncThread.run)在hread.java:818FutureTjava.lang.完成(FutureTin.betterbutter.andro
在中请求位置更新时,我收到此错误。授予位置权限,不为空,不为空。 我在内部调用的位置代码:
我有一个应用程序发布在谷歌play,我在谷歌控制台下面的崩溃报告,谁能帮助我了解这个问题是从哪里来的,如何得到解决。 java.lang.RuntimeException:在android.app.activitythread.handlereceiver(activitythread.java:3523)在android.app.activitythread.access$1400(activi