gpt4 book ai didi

java - Android - ASyncTask 错误 ThreadPoolExecutor

转载 作者:行者123 更新时间:2023-12-01 13:19:11 25 4
gpt4 key购买 nike

我正在尝试在后台下载文件。我没有更改任何与文件下载或异步任务有关的内容,突然间它不再起作用了。这是我的 LogCat:

    03-04 17:51:45.485: W/System.err(1481): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
03-04 17:51:45.485: W/System.err(1481): at libcore.io.Posix.open(Native Method)
03-04 17:51:45.485: W/System.err(1481): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
03-04 17:51:45.485: W/System.err(1481): at libcore.io.IoBridge.open(IoBridge.java:393)
03-04 17:51:45.485: W/System.err(1481): ... 14 more
03-04 17:51:45.765: W/dalvikvm(1481): threadid=11: thread exiting with uncaught exception (group=0xb4af3b90)
03-04 17:51:45.865: E/AndroidRuntime(1481): FATAL EXCEPTION: AsyncTask #1
03-04 17:51:45.865: E/AndroidRuntime(1481): Process: com.csc.android.industryforum, PID: 1481
03-04 17:51:45.865: E/AndroidRuntime(1481): java.lang.RuntimeException: An error occured while executing doInBackground()
03-04 17:51:45.865: E/AndroidRuntime(1481): at android.os.AsyncTask$3.done(AsyncTask.java:300)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-04 17:51:45.865: E/AndroidRuntime(1481): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.lang.Thread.run(Thread.java:841)
03-04 17:51:45.865: E/AndroidRuntime(1481): Caused by: java.lang.NullPointerException: lock == null
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.io.Reader.<init>(Reader.java:64)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.io.InputStreamReader.<init>(InputStreamReader.java:122)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.io.InputStreamReader.<init>(InputStreamReader.java:59)
03-04 17:51:45.865: E/AndroidRuntime(1481): at com.csc.android.industryforum.MainActivity.readFileArray(MainActivity.java:902)
03-04 17:51:45.865: E/AndroidRuntime(1481): at com.csc.android.industryforum.MainActivity.handleMenuInfo(MainActivity.java:355)
03-04 17:51:45.865: E/AndroidRuntime(1481): at com.csc.android.industryforum.MainActivity.access$1(MainActivity.java:342)
03-04 17:51:45.865: E/AndroidRuntime(1481): at com.csc.android.industryforum.MainActivity$DownloadTask.doInBackground(MainActivity.java:1023)
03-04 17:51:45.865: E/AndroidRuntime(1481): at com.csc.android.industryforum.MainActivity$DownloadTask.doInBackground(MainActivity.java:1)
03-04 17:51:45.865: E/AndroidRuntime(1481): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-04 17:51:45.865: E/AndroidRuntime(1481): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-04 17:51:45.865: E/AndroidRuntime(1481): ... 4 more
03-04 17:51:46.485: I/Choreographer(1481): Skipped 72 frames! The application may be doing too much work on its main thread.
03-04 17:51:46.925: I/Choreographer(1481): Skipped 65 frames! The application may be doing too much work on its main thread.
03-04 17:51:48.615: E/WindowManager(1481): android.view.WindowLeaked: Activity com.csc.android.industryforum.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b4dcd940 V.E..... R.....ID 0,0-424,140} that was originally added here
03-04 17:51:48.615: E/WindowManager(1481): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:346)
03-04 17:51:48.615: E/WindowManager(1481): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
03-04 17:51:48.615: E/WindowManager(1481): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.Dialog.show(Dialog.java:286)
03-04 17:51:48.615: E/WindowManager(1481): at com.csc.android.industryforum.MainActivity.loadFiles(MainActivity.java:136)
03-04 17:51:48.615: E/WindowManager(1481): at com.csc.android.industryforum.MainActivity.onCreate(MainActivity.java:99)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.Activity.performCreate(Activity.java:5243)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.ActivityThread.access$700(ActivityThread.java:135)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
03-04 17:51:48.615: E/WindowManager(1481): at android.os.Handler.dispatchMessage(Handler.java:102)
03-04 17:51:48.615: E/WindowManager(1481): at android.os.Looper.loop(Looper.java:137)
03-04 17:51:48.615: E/WindowManager(1481): at android.app.ActivityThread.main(ActivityThread.java:4998)
03-04 17:51:48.615: E/WindowManager(1481): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 17:51:48.615: E/WindowManager(1481): at java.lang.reflect.Method.invoke(Method.java:515)
03-04 17:51:48.615: E/WindowManager(1481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
03-04 17:51:48.615: E/WindowManager(1481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
03-04 17:51:48.615: E/WindowManager(1481): at dalvik.system.NativeStart.main(Native Method)

根据答案之一,问题出在我的文件读取上,所以这是代码:

private ArrayList<String> readFileArray(File file){
FileInputStream in = null;
try {
in = openFileInput(file.getName());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStreamReader inputStreamReader = new InputStreamReader(in);//this is line 902
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line;
String line1 = "";
ArrayList<String> ar1 = new ArrayList<String>();
try {
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
ar1.add(line);
if (line1.equals("")){
line1 = line1 + line;
}else{
line1 = line1 + "\n" + line;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ar1;

}

这是调用该代码的代码:

    private String[] handleMenuInfo(String selection){
DataClass dc = new DataClass(this);

File dir = getDir("myDir", Context.MODE_PRIVATE);
File file = new File(dir, selection + ".txt");
ArrayList <String> menuArray;

menuArray = readFileArray(file);
String[] menuList = menuArray.toArray(new String[menuArray.size()]);
return menuList;
//}

}

这是 ASyncTask

 private class DownloadTask extends AsyncTask<Integer, Void, Void> {

private Context context;
private PowerManager.WakeLock mWakeLock;

public DownloadTask(Context context) {
this.context = context;
}

@Override
protected void onPreExecute() {

}

protected void onPostExecute() {

}

@Override
protected Void doInBackground(Integer... sUrl) {

DataClass dc = new DataClass(c);
//ArrayList<String> menuArray = dc.getMenuArray("Home");
String[] menuArray = {"Home", "Announcements", "Speakers", "Events", "Exhibitors", "Agenda", "Hotels", "Documents"};
File dir = getDir("myDir", Context.MODE_PRIVATE);

for(int i=1; i <= 7; i++){
String[] menuList = handleMenuInfo(menuArray[i]);
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(7);
mProgressDialog.setProgress(i);
for(int i2=1; i2 < menuList.length; i2++){
File file = new File(dir, menuArray[i] + "/" + menuList[i2] + ".txt");
ArrayList<String> viewArray = dc.getInfoArray(menuArray[i],menuList[i2]);
writeToFile(file, viewArray);

}
}
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
Editor editor = sharedPreferences.edit();
editor.putString("new", "No");
editor.commit();
mProgressDialog.dismiss();
return null;


}
}


}

最佳答案

纯粹根据您提供的堆栈跟踪,您似乎遇到了 this problem 。在 MainActivity.DownloadTask 中,您将未初始化的 FileInputStream 传递到 InputStreamReader 中。

问题在于 MainActivity 第 902 行中使用的 InputStream 的实例化。

关于java - Android - ASyncTask 错误 ThreadPoolExecutor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22184994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com