Android DismissDialog 的 IllegalArgumentException

2024-07-03

我使用以下代码从我们的互联网下载一些文件。

public class SplashDownload extends Activity {

    public static final int PROGRESS_DIALOG = 0;
    private ProgressDialog mProgressDialog;
    private WordDataHelper wordDataHelper;
    private ExtraDataHelper extraDataHelper;

    // put your file path here
    private String filePath = "http://test.com/Assets/";
    // put your filename here
    private String fileName;
    // put your download directory name here
    private String downloadDir;

    private int wordCounter = 0, extraCounter = 0, counter = 1;

    private boolean wordDLOn = true;
    private int totalFileNo;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashdllayout);
        getDownloadList();
    }

    private void goForward() {

        Intent intent = new Intent().setClass(this, LangH.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }

    private void doNext() {

        if (wordDLOn) {

            System.out.print("wordDetails update: "
                    + wordDetails[wordCounter - 1][0]
                    + extraDetails[extraCounter][0] + fileName);
            wordDataHelper.updateDLStat(Long
                    .valueOf(wordDetails[wordCounter - 1][0]));
        } else {

            System.out.print("extraDetails update: "
                    + extraDetails[extraCounter - 1][0] + fileName);
            extraDataHelper.updateDLStat(Long
                    .valueOf(extraDetails[extraCounter - 1][0]));
        }

        if (wordCounter < wordDetails.length) {
            System.out.print("wordCounter: " + wordCounter + "/"
                    + wordDetails.length);
            startDownload(wordDetails[wordCounter][1]);
            wordCounter++;
        } else if (extraCounter < extraDetails.length) {
            wordDLOn = false;
            downloadDir = "LanH/extras";
            System.out.print("extraCounter: " + extraCounter + "/"
                    + extraDetails.length);
            startDownload(extraDetails[extraCounter][1]);
            extraCounter++;
        } else {
            goForward();
        }
    }

    private void getDownloadList() {

        // lessons download..........

        String[] wordDetails = {"1.mp4","2.mp4","3.mp4","4.mp4","5.mp4","6.mp4","7.mp4","8.mp4",};
        downloadDir = "LanH/words";


        String[] extraDetails = {"a.mp4","b.mp4","c.mp4","d.mp4","e.mp4","f.mp4","g.mp4","h.mp4",};


        totalFileNo = extraDetails.length + wordDetails.length;

        if (wordDetails.length != 0) {
            startDownload(wordDetails[wordCounter]);
            wordCounter++;
        } else if (extraDetails.length != 0) {
            wordDLOn = false;
            startDownload(extraDetails[extraCounter]);
            extraCounter++;
        } else {
            goForward();
        }

    }

    private void startDownload(String dlFilename) {
        // tv = (TextView) findViewById(R.id.tv1);
        fileName = dlFilename;
        System.out.print("fileName: " + fileName);

        File dir = new File(android.os.Environment
                .getExternalStorageDirectory().getAbsolutePath()
                + "/"
                + downloadDir);
        // creates the directory if it doesn't exists
        if (dir.exists() == false) {
            dir.mkdirs();
        }
        dir = null;

        if (checkNet()) {
            if (checkExternalMedia() == true) {
                String url = filePath + fileName;
                new DownloadFileAsync().execute(url, fileName);
                mProgressDialog.setMessage("Downloading file.." + fileName);
            } else {
                Toast.makeText(getApplicationContext(),
                        "External Media is NOT readable/writable",
                        Toast.LENGTH_SHORT).show();
            }
        } else {

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("No Internet Connectivity. Check the connection and retry the app.")
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int id) {
                            finish();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    }


    /** Method to check whether external media available and writable. */
    private boolean checkExternalMedia() {
        boolean stat;
        String state = Environment.getExternalStorageState();

        if (Environment.MEDIA_MOUNTED.equals(state)) {
            // Can read and write the media
            stat = true;
        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            // Can only read the media
            stat = false;
        } else {
            // Can't read or write
            stat = false;
        }
        return stat;
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case PROGRESS_DIALOG:
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage("Downloading file.." + fileName);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgressDialog.setCancelable(false);
            mProgressDialog.show();
            return mProgressDialog;
        default:
            return null;
        }
    }

    class DownloadFileAsync extends AsyncTask<String, String, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            showDialog(PROGRESS_DIALOG);
        }

        @Override
        protected String doInBackground(String... aurl) {
            int count;

            try {
                URL url = new URL(aurl[0]);
                URLConnection conexion = url.openConnection();
                conexion.connect();

                int lenghtOfFile = conexion.getContentLength();
                Log.d("DOWNLOAD_TEST", "Lenght of file: " + lenghtOfFile);

                InputStream input = new BufferedInputStream(url.openStream());
                OutputStream output = new FileOutputStream(
                        android.os.Environment.getExternalStorageDirectory()
                                + "/" + downloadDir + "/" + aurl[1]);

                byte data[] = new byte[1024];

                long total = 0;

                while ((count = input.read(data)) != -1) {
                    total += count;
                    publishProgress("" + (int) ((total * 100) / lenghtOfFile));
                    output.write(data, 0, count);
                }

                output.flush();
                output.close();
                input.close();
            } catch (Exception e) {
            }
            return null;

        }

        protected void onProgressUpdate(String... progress) {
            Log.d("DOWNLOAD_TEST", progress[0]);
            mProgressDialog.setProgress(Integer.parseInt(progress[0]));
        }

        @Override
        protected void onPostExecute(String unused) { 

            dismissDialog(PROGRESS_DIALOG);

            // tv.append("\n\nFile Download Complete!");
            // Button btn = (Button) findViewById(R.id.btn1);
            // btn.setVisibility(View.GONE);

            // you can call a second intent here to redirect to another screen
            doNext();
        }
    }

    private boolean checkNet() {
        boolean connected = false;
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
                .getState() == NetworkInfo.State.CONNECTED
                || connectivityManager.getNetworkInfo(
                        ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
            // we are connected to a network
            connected = true;
        } else
            connected = false;
        return connected;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
}

该过程运行良好。据报道,崩溃报告如下:

java.lang.IllegalArgumentException: no dialog with id 0 was ever shown via Activity#showDialog
at android.app.Activity.missingDialog(Activity.java:2663)
at android.app.Activity.dismissDialog(Activity.java:2648)
at com.langhost.main.SplashDownload$DownloadFileAsync.onPostExecute(SplashDownload.java:264)
at com.langhost.main.SplashDownload$DownloadFileAsync.onPostExecute(SplashDownload.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5068)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

我的代码有什么问题?是isShowing()之前检查dismissDialog会解决问题吗?


你的进度对话框真的显示了吗?
您可以尝试使用而不是忽略它removeDialog(PROGRESS_DIALOG);把它清理干净。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android DismissDialog 的 IllegalArgumentException 的相关文章

  • New Relic Android 代理在 gradle 时出现错误

    我有一个使用 gradle 构建系统的项目 我愿意向其中添加 New Relic 监控 该项目 包括 New Relic 在 Linux Fedora 20 上运行良好 但无法在我的 Mac 开发系统上构建 并给出错误说明Agent JAR
  • WorkManager 的 doWork() 为 OneTimeWorkRequest 多次调用

    我才刚刚开始探索WorkManager在我的应用程序中 我的应用程序大部分都是离线的 因此所有数据都使用 room db 存储在本地 一旦设备连接到网络 我想将本地数据同步到服务器 然后获取最新数据并再次同步本地数据库 这是我的doWork
  • 如何知道活动何时安排?

    我有一个地图视图 我想在其上放置一些标记 当我开始活动时 我将从网络服务中检索这些数据 因此我需要知道当前视口的最小和最大纬度 经度对 我正在打电话 mMapView getWidth mMapView getHeight 但当活动开始时它
  • Android 4.0 与 Canvas.clipPath 的兼容性问题

    最近 我的应用程序收到了很多评论 说 它在带有 CM9 的 Android Ice Cream Sandwich 上不起作用 我无法在运行 Android 4 0 的模拟器上重现该错误 并且由于 Android 市场的工作方式 我无法联系那
  • 如何更改时间选择器和日期选择器的文本颜色?

    目前我正在开发我的第一个应用程序 在这个应用程序中我有一个TimePicker and a DatePicker 我现在的Activity有深色背景 现在我想要一个白色的文本颜色TimePicker DatePicker 在我的布局中 我定
  • Y'UV420p(和 Y'V12 或 YV12)到 RGB888 转换

    我正在尝试在 android 中显示 yuv 视频文件 我有一些正在使用的 yuv 视频文件 该视频yuv文件video1 https www dropbox com s wjofvdf9k9bglhx rawData1 yuv dl 0
  • 使用带有离子和电容器的 https 加载 webview

    我正在尝试构建一个必须加载的 apkhttps mydomain https mydomain与离子4和电容器 在 Capacitor config json 中 我精确了这个字段 server hostname mydomain 因为我在
  • 应用内结算:库存不正确;让用户再次购买

    编辑 仍在寻找我原来问题的答案 为什么 Android 不会看到该商品之前已购买过 而是让用户再次付款 设置 SharedPreferences 是一个不错的主意 但是如果用户卸载了怎么办 他们将不得不再次购买 我不希望用户这样 谢谢 我试
  • 仅第一行断点有效

    I am developing in Android Studio i ve used IntelliJ IDEA SDK I ve encountered debugging problem All my breakpoints don
  • HTC Desire 上的 EGLConfig,可用配置挂起设备

    我正在实施我自己的EGLConfigChooser传递给setEGLConfigChooser 为了根据我对应用程序的需求为当前设备选择最佳的可用配置 更具体地说 我正在查询所有可用的配置并选择具有最大深度缓冲区大小的配置 在具有相同深度缓
  • 隐藏另一个布局的浮动操作按钮

    我有一个FloatingActionButton五月之内activity main xml名为的布局fabBtn 我的应用程序是用ViewPager和三个Fragments 我想隐藏FloatingActionButton当我的第一次Fra
  • getAllNetworkInfo() 在 M 中已弃用,但其替代品具有不同的行为

    ConnectivityManager 的 getAllNetworkInfo 在 API 23 上已弃用 其注释表示使用 getAllNetworks 代替 然而我发现这些没有相同的行为 例如 如果手机有可用的活动蜂窝网络 但 wifi
  • 如何用多个手指在画布上绘图

    我正在使用安卓Canvas创建绘图应用程序的类 这是我第一次尝试使用 Canvas 类 到目前为止 我使用的代码工作正常 绘图工作正常 但我在这段代码中意识到 它允许用户仅用一根手指进行绘画 我的意思是说 如果用户使用多于一根手指在画布上绘
  • 应用已被 Google Play 删除,因为旧版本不符合新的后台位置政策

    我调整了位置数据的权限和使用 并将其发布在新版本 v10004 中 不幸的是 我的应用程序仍然被删除 因为以前的版本不符合新的后台位置规定 如我从 Google 收到的邮件中所述 受影响的 APK App Bundle v10003 我找不
  • 清单合并 - Android studio 0.8.1 升级构建错误:属性“manifestFile”不存在

    我刚刚升级到 Android Studio 0 8 1 并升级了构建工具等 来自 Android Studio 0 6 但后来我得到了这个构建错误 发现任务配置有问题 processDevelopmentDebugResources 文件
  • Proguard 损坏可绘制文件

    我对 proguard 有一个奇怪的问题 不知何故它破坏了我的有效可绘制文件 没有proguard的drawable显示可以 proguard 应该缩小 xml 可绘制对象吗 可绘制 wide btn round white xml
  • Android 嵌套片段问题“java.lang.IllegalStateException:活动已被销毁”

    您可能知道 Android 支持嵌套片段 也是通过 API 级别 17 的支持库实现的 所以基本上我正在尝试将嵌套片段添加到 ViewPager 的片段之一中 并熟悉这一新的好功能 在第一次应用程序启动时 一切都按预期工作 即我可以添加子片
  • Azure 移动应用程序 node.js 后端 Android 客户端 - 50 行限制

    我一直在尝试获取 Azure 移动应用程序返回的超过 50 行结果 但到目前为止没有成功 我已经尝试过以下方法 A Top 100 Skip 100 gt 这个解决方案在我的上下文中对我来说没有用 b 有人建议我尝试将 app js 中的
  • appcompat 在操作栏中显示进度导致 NPE

    将我的 SDK 更新到所有最新的 Android 5 0 后 我无法使用 appcompat 中 ActionBar 中内置的进度条 我已经完成了所有通常的修复 将 supportRequestWindowFeature 调用移至 setC
  • 启动应用程序时反应本机 Android 错误

    V SoLoader libimagepipeline so not found on data data com learnapp lib main D SoLoader libimagepipeline so found on data

随机推荐

  • Socket.io 0.7.9 连接问题

    我正在尝试升级到 socket io 0 7 9 但遇到了问题 我使用了 socket io 主页上的基本示例 我的服务器是 var http require http url require url https require https
  • Socket.io 0.7.9 连接问题

    我正在尝试升级到 socket io 0 7 9 但遇到了问题 我使用了 socket io 主页上的基本示例 我的服务器是 var http require http url require url https require https
  • 如何使用 Laravel Eloquent 获取特定成绩数据?

    我想要的是 为了得到grade数据库中存在用户回答的内容 如果存在 并获取该答案的等级 我拥有的 I have 3桌子 short answer sa sa answer short answer answer Now short answ
  • 如何使用 Laravel Eloquent 获取特定成绩数据?

    我想要的是 为了得到grade数据库中存在用户回答的内容 如果存在 并获取该答案的等级 我拥有的 I have 3桌子 short answer sa sa answer short answer answer Now short answ
  • REST - PUT 方法在省略可选字段时是否必须删除该字段?

    我有资源Car其中有一些必填字段和其他可选字段 The Car是根据以下请求创建的 POST cars plate XYZ A2C4 color blue owner John OPTIONAL REST 客户端想要更新这辆车的所有必需信息
  • REST - PUT 方法在省略可选字段时是否必须删除该字段?

    我有资源Car其中有一些必填字段和其他可选字段 The Car是根据以下请求创建的 POST cars plate XYZ A2C4 color blue owner John OPTIONAL REST 客户端想要更新这辆车的所有必需信息
  • 如何从图库中获取图像的图像格式

    我想知道我从图库中获取的图像的图像格式 即 JPG PNG 等 我的需要是从设备的图库中获取图像并将其以 Base64 格式发送到服务器 但服务器想知道图像格式 任何帮助表示赞赏 Edited 使用以下方法从图库中检索图像的 MIME 类型
  • 如何从图库中获取图像的图像格式

    我想知道我从图库中获取的图像的图像格式 即 JPG PNG 等 我的需要是从设备的图库中获取图像并将其以 Base64 格式发送到服务器 但服务器想知道图像格式 任何帮助表示赞赏 Edited 使用以下方法从图库中检索图像的 MIME 类型
  • 如何在 JSF 2 中以编程方式或动态创建复合组件

    我需要在 JSF 2 中以编程方式创建复合组件 经过几天的搜索和实验 我找到了这个方法 深受 java net 上的 Lexi 的启发 Method will attach composite component to provided c
  • 如何在 JSF 2 中以编程方式或动态创建复合组件

    我需要在 JSF 2 中以编程方式创建复合组件 经过几天的搜索和实验 我找到了这个方法 深受 java net 上的 Lexi 的启发 Method will attach composite component to provided c
  • 同步时间 C#

    我有一个 C net 程序 部署在不同的机器上 我希望该程序的所有实例都使用与 Windows 时间服务器同步的 DateTime 变量 最好的方法是什么 更新开始 我能想到的另一种方法是公开一个服务 该服务将在其运行的计算机中返回 UTC
  • 同步时间 C#

    我有一个 C net 程序 部署在不同的机器上 我希望该程序的所有实例都使用与 Windows 时间服务器同步的 DateTime 变量 最好的方法是什么 更新开始 我能想到的另一种方法是公开一个服务 该服务将在其运行的计算机中返回 UTC
  • 表现不佳

    我正在为我的硕士论文进行性能测试 但 Symfony2 简单应用程序的性能非常差 这是一个简单的应用程序 一个查询和一些数学运算 命令测试结果 ab c10 t60http sf2 cities localhost app php http
  • 表现不佳

    我正在为我的硕士论文进行性能测试 但 Symfony2 简单应用程序的性能非常差 这是一个简单的应用程序 一个查询和一些数学运算 命令测试结果 ab c10 t60http sf2 cities localhost app php http
  • 目前没有可用的原型。当索引更新完成时,原型列表将刷新

    在 Eclipse 中m2eclipse安装后 当我选择 文件 gt 新建 gt 项目 gt Maven gt Maven 项目 with 使用默认工作区位置 and 目录 Nexus 索引器 选择后 出现以下错误消息 目前没有可用的原型
  • 目前没有可用的原型。当索引更新完成时,原型列表将刷新

    在 Eclipse 中m2eclipse安装后 当我选择 文件 gt 新建 gt 项目 gt Maven gt Maven 项目 with 使用默认工作区位置 and 目录 Nexus 索引器 选择后 出现以下错误消息 目前没有可用的原型
  • 为 Google 表单生成自己的 HTML

    我喜欢使用我自己的模板引擎生成 Google 表单 不幸的是 在基本主题中 您只能更改背景图像 字体 颜色等 我喜欢 bootstrap 风格的漂亮 HTML 页面 到目前为止 我可以看到我可以使用 Google 脚本来做到这一点 该脚本应
  • 为 Google 表单生成自己的 HTML

    我喜欢使用我自己的模板引擎生成 Google 表单 不幸的是 在基本主题中 您只能更改背景图像 字体 颜色等 我喜欢 bootstrap 风格的漂亮 HTML 页面 到目前为止 我可以看到我可以使用 Google 脚本来做到这一点 该脚本应
  • Android DismissDialog 的 IllegalArgumentException

    我使用以下代码从我们的互联网下载一些文件 public class SplashDownload extends Activity public static final int PROGRESS DIALOG 0 private Prog
  • Android DismissDialog 的 IllegalArgumentException

    我使用以下代码从我们的互联网下载一些文件 public class SplashDownload extends Activity public static final int PROGRESS DIALOG 0 private Prog