Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “进度”对话框出现问题,Android Studio无法继续_Java_Android_Sqlite - Fatal编程技术网

Java “进度”对话框出现问题,Android Studio无法继续

Java “进度”对话框出现问题,Android Studio无法继续,java,android,sqlite,Java,Android,Sqlite,我的进度对话框有问题。“进度”对话框出现,但我看不到任何进度。我不知道我做错了什么。这是我的代码: case R.id.fill_metal_pieces_table: MyApplication myApp = ((MyApplication)getActivity().getApplicationContext()); boolean tablepopulated = myApp.getMetalPiecesTablePopulated();

我的进度对话框有问题。“进度”对话框出现,但我看不到任何进度。我不知道我做错了什么。这是我的代码:

case R.id.fill_metal_pieces_table:
            MyApplication myApp = ((MyApplication)getActivity().getApplicationContext());
            boolean tablepopulated = myApp.getMetalPiecesTablePopulated();
            if(tablepopulated == false){
                myApp.setMetalPiecesTablePopulated(true);
                progressDialog = new ProgressDialog(getContext());
                progressDialog.setIndeterminate(false);
                progressDialog.setMax(652);
                progressDialog.setMessage("Chargement...");
                progressDialog.setTitle("Remplissage de la table");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                progressDialog.setCancelable(false);
                progressDialog.show();
                new Thread(new Runnable() {
                    public void run() {
                        Looper.prepare();
                        handler = new Handler(Looper.myLooper()){
                            public void handleMessage(Message msg) {
                                super.handleMessage(msg);
                                progressDialog.incrementProgressBy(msg.what);
                            }
                        };
                        Looper.loop();
                        AssetManager am = getContext().getAssets();
                        InputStream is = null;
                        try {
                            is = am.open("catalogue.xls");
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        Workbook wb = null;
                        try {
                            wb = Workbook.getWorkbook(is);
                        } catch (IOException e) {
                            e.printStackTrace();
                        } catch (BiffException e) {
                            e.printStackTrace();
                        }
                        Sheet sheet = wb.getSheet(0);
                        DBAdapter db = new DBAdapter(getContext());
                        MetalPiece metalPiece;
                        for(int row = 1; row <= 652; row ++){
                            String typeMetalPiece = sheet.getCell(0, row).getContents();
                            String weightMetalPiece = sheet.getCell(1, row).getContents();
                            metalPiece = new MetalPiece();
                            metalPiece.setType(typeMetalPiece);
                            metalPiece.setWeight(Float.parseFloat(weightMetalPiece));
                            metalPiece.setFamily("Profile");
                            metalPiece.setUnit("Métre");
                            db.saveMetalPiece(metalPiece);
                            handler.sendEmptyMessage(1);
                        }
                        progressDialog.dismiss();
                        intent = new Intent(getContext(), MainActivity.class);
                        intent.putExtra("tab","metalpiece");
                        startActivity(intent);
                    }
                }).start();
            }
            else{
                Toast statusMetalPiecesTable = Toast.makeText(getContext(), "La table des piéces métalliques est déja remplie",Toast.LENGTH_LONG);
                statusMetalPiecesTable.show();
            }
            return true;
case R.id.填充金属片表:
MyApplication myApp=((MyApplication)getActivity().getApplicationContext());
布尔tablepopulated=myApp.getMetalPiecesTablePopulated();
if(tablepopulated==false){
myApp.setMetalPiecesTablePopulated(真);
progressDialog=新建progressDialog(getContext());
progressDialog.setUndeterminate(false);
progressDialog.setMax(652);
progressDialog.setMessage(“计费…”);
progressDialog.setTitle(“Remplissage de la table”);
progressDialog.setProgressStyle(progressDialog.STYLE_水平);
progressDialog.setCancelable(假);
progressDialog.show();
新线程(newrunnable()){
公开募捐{
Looper.prepare();
handler=新处理程序(Looper.myLooper()){
公共无效handleMessage(消息消息消息){
超级handleMessage(msg);
progressDialog.incrementProgressBy(msg.what);
}
};
loop.loop();
AssetManager am=getContext().getAssets();
InputStream=null;
试一试{
is=上午开放(“catalog.xls”);
}捕获(IOE异常){
e、 printStackTrace();
}
工作簿wb=null;
试一试{
wb=Workbook.getWorkbook(is);
}捕获(IOE异常){
e、 printStackTrace();
}捕获(双飞例外e){
e、 printStackTrace();
}
Sheet Sheet=wb.getSheet(0);
DBAdapter db=newdbadapter(getContext());
金属件金属件;

对于(int row=1;row尝试将
新处理程序(Looper.myLooper())
替换为
新处理程序(Looper.getMainLooper())
,或者在
线程
外部创建它-因为
进程对话框
应该/必须在主UI
线程
中更新,而不是使用自己的循环更新一些自定义
线程


另外:使用
Log.i(“一些标签”,“一些值”);
记录步骤,并找出哪个部分代码没有正确执行(
handleMessage
是否会收到这些消息以重定向到
progressDialog
?放入
handleMessage
方法
Log.i(“一些标签”,“handleMessage msg.what:+msg.what”);
).日志显示在IDE底部的Android Studio Logcat选项卡中

我尝试了这两种解决方案,但均无效