java-进度条不能运行的问题

问题描述

进度条不能运行的问题

我想填充进度条,但是没有实现。
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
时间: 2024-10-03 03:32:43

java-进度条不能运行的问题的相关文章

关于java进度条的显示问题

问题描述 关于java进度条的显示问题 我的进度条老是显示到36%然后就变成0%了,然后过一段时间又从0开始 我将进度条显示的值打印出来之后发现每次从0增加到36之后会变成-36 然后继续增加,这是怎么回事 解决方案 设置断点跟踪一下,看是不是进度计算出了问题: 解决方案二: 将设置到进度条的数值通过 log 打印出来,这个问题应该是设置的数值出了问题! 解决方案三: 进度条数值计算出问题了.

Java上传文件进度条的实现方法(附demo源码下载)_java

本文实例讲述了Java上传文件进度条的实现方法.分享给大家供大家参考,具体如下: 东西很简单,主要用到commons-fileupload,其中有一个progressListener的接口,该接口可以实现实时更新已上传文件的大小,有了这个还说什么呢? 这里给出代码: package lc.progress; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import lc.

自定义Android六边形进度条(附源码)_Android

本文实例讲述了Android自定义圆形进度条,分享给大家供大家参考.具体如下: 大家也可以参考这两篇文章进行学习: <自定义Android圆形进度条(附源码)>   <Android带进度的圆形进度条> 运行效果截图如下: 主要代码: package com.sxc.hexagonprogress; import java.util.Random; import android.content.Context; import android.content.res.ColorSta

PHP实现的进度条效果详解_php技巧

本文实例讲述了PHP实现的进度条效果.分享给大家供大家参考,具体如下: 在做采集的时候,想通过php来实现一个进度条功能,谷歌了一下,找了个合适的代码.下面直接上代码: <?php //防止执行超时 set_time_limit(0); //清空并关闭输出缓存 ob_end_clean(); //需要循环的数据 for($i = 0; $i < 188; $i++) { $users[] = 'Tom_' . $i; } //计算数据的长度 $total = count($users); //

自定义Android六边形进度条(附源码)

本文实例讲述了Android自定义圆形进度条,分享给大家供大家参考.具体如下: 大家也可以参考这两篇文章进行学习: <自定义Android圆形进度条(附源码)>   <Android带进度的圆形进度条> 运行效果截图如下: 主要代码: package com.sxc.hexagonprogress; import java.util.Random; import android.content.Context; import android.content.res.ColorSta

Android实现为Notification加上一个进度条的方法_Android

本文实例讲述了Android实现为Notification加上一个进度条的方法.分享给大家供大家参考,具体如下: package com.notification; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent;

进度条-非阻塞异步处理。敬请高人指点,不胜感激。

问题描述 非阻塞异步处理.敬请高人指点,不胜感激. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>/c:set <!DOCTY

基于Ajax技术实现文件上传带进度条_AJAX相关

1.概述 在实际的Web应该开发或网站开发过程中,经常需要实现文件上传的功能.在文件上传过程中,经常需要用户进行长时间的等待,为了让用户及时了解上传进度,可以在上传文件的同时,显示文件的上传进度条.运行本实例,如图1所示,访问文件上传页面,单击"浏览"按钮选择要上传的文件,注意文件不能超过50MB,否则系统将给出错误提示.选择完要上传的文件后,单击"提交"按钮,将会上传文件并显示上传进度. 2.技术要点 主要是应用开源的Common-FileUpload组件来实现分

Android实现支持进度条显示的短信备份工具类_Android

使用内容提供者读取短信内容,写入XML文件,进度条ProgressDialog更新备份进度.新知识点:子线程如何在在不使用Handler的情况下更新UI /** * 进行短信备份的工具类,支持进度条显示 * @author lian * */ public class SmsBackupUtils { private static class Data{ int progress; } /** * * @param context * 调用此工具类的Activity * @param pd *