ssummeraw 2013-09-10 09:17 采纳率: 10%
浏览 901

进度条不能运行的问题

我想填充进度条,但是没有实现。
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

Exception:

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
  • 写回答

1条回答

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-25 19:58
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功