プログレスバーに入力しようとしているコードの何が問題になっていますが、入力されません。
私のMainActivityは
package com.example.progressbar;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.ProgressDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public abstract class MainActivity2 extends Activity {
int progressStatus = 0;
int fileSize = 0;
ProgressDialog progress;
Button button;
Handler h=new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonClick();
}
public void buttonClick(){
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
progress=new ProgressDialog(v.getContext());
progress.setCancelable(true);
progress.setMessage("File Downloading..");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setProgress(0);
progress.setMax(100);
progress.show();
new Thread(new Runnable() {
@Override
public void run() {
while (progressStatus<=100) {
progressStatus=doOperation();
try{
Thread.sleep(1000);
} //end of try
catch (Exception e) {
e.printStackTrace();
}// End of the Catch
h.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
progress.setProgress(progressStatus);
}); //end of post
} // end of while
if (progressStatus>=100)
{
try{
Thread.sleep(4000);
}catch (Exception e) {
e.printStackTrace();
}
progress.dismiss();
}
} // end of run
}).start();
} //end of on click method
}); //end of new on click listener
}
private int doOperation() {
while(fileSize<=10000){
++fileSize;
if(fileSize==1000){
return 10;
}
if(fileSize==2000){
return 20;
}
if(fileSize==3000){
return 30;
}
if(fileSize==4000){
return 40;
}
if(fileSize==5000){
return 50;
}
if(fileSize==6000){
return 60;
}
if(fileSize==7000){
return 70;
}
if(fileSize==8000){
return 80;
}
if(fileSize==9000){
return 90;
}
if(fileSize==10000){
return 100;
}
//end of while
return 100;
} // end of doOperation()
} // End of the class
例外
09-10 09:56:12.719: D/dalvikvm(553): newInstance failed: p0 i0 [0 a1
09-10 09:56:12.770: D/AndroidRuntime(553): Shutting down VM
09-10 09:56:12.770: W/dalvikvm(553): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-10 09:56:12.890: E/AndroidRuntime(553): FATAL EXCEPTION: main
09-10 09:56:12.890: E/AndroidRuntime(553): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.progressbar/com.example.progressbar.MainActivity}: java.lang.InstantiationException: com.example.progressbar.MainActivity
09-10 09:56:12.890: E/AndroidRuntime(553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.os.Looper.loop(Looper.java:123)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 09:56:12.890: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 09:56:12.890: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 09:56:12.890: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 09:56:12.890: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 09:56:12.890: E/AndroidRuntime(553): at dalvik.system.NativeStart.main(Native Method)
09-10 09:56:12.890: E/AndroidRuntime(553): Caused by: java.lang.InstantiationException: com.example.progressbar.MainActivity
09-10 09:56:12.890: E/AndroidRuntime(553): at java.lang.Class.newInstanceImpl(Native Method)
09-10 09:56:12.890: E/AndroidRuntime(553): at java.lang.Class.newInstance(Class.java:1429)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-10 09:56:12.890: E/AndroidRuntime(553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
09-10 09:56:12.890: E/AndroidRuntime(553): ... 11 more
09-10 09:59:38.939: D/dalvikvm(581): newInstance failed: p0 i0 [0 a1
09-10 09:59:38.939: D/AndroidRuntime(581): Shutting down VM
09-10 09:59:38.979: W/dalvikvm(581): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-10 09:59:39.059: E/AndroidRuntime(581): FATAL EXCEPTION: main
09-10 09:59:39.059: E/AndroidRuntime(581): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.progressbar/com.example.progressbar.MainActivity}: java.lang.InstantiationException: com.example.progressbar.MainActivity
09-10 09:59:39.059: E/AndroidRuntime(581): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.os.Looper.loop(Looper.java:123)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 09:59:39.059: E/AndroidRuntime(581): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 09:59:39.059: E/AndroidRuntime(581): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 09:59:39.059: E/AndroidRuntime(581): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 09:59:39.059: E/AndroidRuntime(581): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 09:59:39.059: E/AndroidRuntime(581): at dalvik.system.NativeStart.main(Native Method)
09-10 09:59:39.059: E/AndroidRuntime(581): Caused by: java.lang.InstantiationException: com.example.progressbar.MainActivity
09-10 09:59:39.059: E/AndroidRuntime(581): at java.lang.Class.newInstanceImpl(Native Method)
09-10 09:59:39.059: E/AndroidRuntime(581): at java.lang.Class.newInstance(Class.java:1429)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-10 09:59:39.059: E/AndroidRuntime(581): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
09-10 09:59:39.059: E/AndroidRuntime(581): ... 11 more
09-10 10:04:39.199: I/Process(581): Sending signal. PID: 581 SIG: 9
09-10 10:09:58.549: D/dalvikvm(609): newInstance failed: p0 i0 [0 a1
09-10 10:09:58.590: D/AndroidRuntime(609): Shutting down VM
09-10 10:09:58.590: W/dalvikvm(609): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-10 10:09:58.629: E/AndroidRuntime(609): FATAL EXCEPTION: main
09-10 10:09:58.629: E/AndroidRuntime(609): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.progressbar/com.example.progressbar.MainActivity}: java.lang.InstantiationException: com.example.progressbar.MainActivity
09-10 10:09:58.629: E/AndroidRuntime(609): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.os.Looper.loop(Looper.java:123)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 10:09:58.629: E/AndroidRuntime(609): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 10:09:58.629: E/AndroidRuntime(609): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 10:09:58.629: E/AndroidRuntime(609): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 10:09:58.629: E/AndroidRuntime(609): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 10:09:58.629: E/AndroidRuntime(609): at dalvik.system.NativeStart.main(Native Method)
09-10 10:09:58.629: E/AndroidRuntime(609): Caused by: java.lang.InstantiationException: com.example.progressbar.MainActivity
09-10 10:09:58.629: E/AndroidRuntime(609): at java.lang.Class.newInstanceImpl(Native Method)
09-10 10:09:58.629: E/AndroidRuntime(609): at java.lang.Class.newInstance(Class.java:1429)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-10 10:09:58.629: E/AndroidRuntime(609): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
09-10 10:09:58.629: E/AndroidRuntime(609): ... 11 more
09-10 10:10:05.819: I/Process(609): Sending signal. PID: 609 SIG: 9
09-10 10:17:26.139: W/KeyCharacterMap(723): No keyboard for id 0
09-10 10:17:26.150: W/KeyCharacterMap(723): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-10 10:19:15.472: W/KeyCharacterMap(781): No keyboard for id 0
09-10 10:19:15.472: W/KeyCharacterMap(781): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-10 10:43:31.709: D/dalvikvm(866): newInstance failed: p0 i0 [0 a1
09-10 10:43:31.709: D/AndroidRuntime(866): Shutting down VM
09-10 10:43:31.740: W/dalvikvm(866): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-10 10:43:31.759: E/AndroidRuntime(866): FATAL EXCEPTION: main
09-10 10:43:31.759: E/AndroidRuntime(866): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.progressbar/com.example.progressbar.MainActivity2}: java.lang.InstantiationException: com.example.progressbar.MainActivity2
09-10 10:43:31.759: E/AndroidRuntime(866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.os.Looper.loop(Looper.java:123)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 10:43:31.759: E/AndroidRuntime(866): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 10:43:31.759: E/AndroidRuntime(866): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 10:43:31.759: E/AndroidRuntime(866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 10:43:31.759: E/AndroidRuntime(866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 10:43:31.759: E/AndroidRuntime(866): at dalvik.system.NativeStart.main(Native Method)
09-10 10:43:31.759: E/AndroidRuntime(866): Caused by: java.lang.InstantiationException: com.example.progressbar.MainActivity2
09-10 10:43:31.759: E/AndroidRuntime(866): at java.lang.Class.newInstanceImpl(Native Method)
09-10 10:43:31.759: E/AndroidRuntime(866): at java.lang.Class.newInstance(Class.java:1429)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-10 10:43:31.759: E/AndroidRuntime(866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
09-10 10:43:31.759: E/AndroidRuntime(866): ... 11 more