ここでAsyncTask
内のループに入るときにテキストビューを更新する方法を考えています。
for (int i = 0; i < buffer.length; i += bufferLength) {
pb.setMax(kbfilesize);
int prog = i/bufferLength;
pb.setProgress(prog);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
textV.setText(pb.getProgress());
}
});
}
}, 0, 100);
outStream1.writeBytes(lineEnd + twoHyphens + boundary + twoHyphens + lineEnd);
}
runOnUiThread
また、使用中に使用する必要がないことを読んだのでAsyncTask
、からUIを更新できますがAsyncTask
、それをしようとするたびに例外が発生します:
05-08 01:12:43.511: W/ResourceType(32344): No package identifier when getting value for resource number 0x00000000
05-08 01:12:43.521: W/dalvikvm(32344): threadid=11: thread exiting with uncaught exception (group=0x41eff2a0)
05-08 01:12:43.531: E/AndroidRuntime(32344): FATAL EXCEPTION: AsyncTask #1
05-08 01:12:43.531: E/AndroidRuntime(32344): java.lang.RuntimeException: An error occured while executing doInBackground()
05-08 01:12:43.531: E/AndroidRuntime(32344): at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.lang.Thread.run(Thread.java:856)
05-08 01:12:43.531: E/AndroidRuntime(32344): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
05-08 01:12:43.531: E/AndroidRuntime(32344): at android.content.res.Resources.getText(Resources.java:242)
05-08 01:12:43.531: E/AndroidRuntime(32344): at android.widget.TextView.setText(TextView.java:3800)
05-08 01:12:43.531: E/AndroidRuntime(32344): at com.linesmedia.MainActivity$FileUploadTask.doInBackground(MainActivity.java:255)
05-08 01:12:43.531: E/AndroidRuntime(32344): at com.linesmedia.MainActivity$FileUploadTask.doInBackground(MainActivity.java:1)
05-08 01:12:43.531: E/AndroidRuntime(32344): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-08 01:12:43.531: E/AndroidRuntime(32344): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-08 01:12:43.531: E/AndroidRuntime(32344): ... 4 more
また、私がrunOnUiThread
getanother例外を使用してそれを行ったとしても...何かアイデアはありますか?