W/CursorWrapperInner(8375): Cursor finalized without prior close()

本文探讨了在Android应用中读取短信时遇到的IO异常问题,并提供了修改方法以避免异常抛出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

i am fed up of this issue, don't know actually where is problem, Below is my code :
private void readSMS() throws IOException {
    // TODO Auto-generated method stub
    Log.d("Read SMS","Called");
    ContentResolver cr = context.getContentResolver();
    Uri uri = Uri.parse("content://sms/inbox");
    StringBuilder smsBackup = new StringBuilder(); 
    Cursor messagesCursor = cr.query(uri, new String[] { "_id","address","body","person"}, null,null, null);
    smsBackup.append("SMS Back UP (Total Message(s)::"+messagesCursor.getCount()+") \n\n");

    String name = null;
    if(messagesCursor.getCount() > 0){
        while(messagesCursor.moveToNext()){
            name = null;
            name = getName(messagesCursor.getString(messagesCursor.getColumnIndex("address")));

            if(name==null)
                name = "Sender : " + messagesCursor.getString(messagesCursor.getColumnIndex("address"));

            smsBackup.append("Sender : "+name +"\n"+  "Message : "+messagesCursor.getString(messagesCursor.getColumnIndex("body")) + "\n\n");
        }
    }

    Log.d("InSMS Lenght","::"+smsBackup.toString().length());
}


here is log cat message : W/CursorWrapperInner(8375): Cursor finalized without prior close()



This may be old but here is the reason why.

Don't throw the exception here:

readSMS() throws IOException

instead wrap in a a try catch block like so:

try{
    ContentResolver cr = context.getContentResolver();
    Uri uri = Uri.parse("content://sms/inbox");
    StringBuilder smsBackup = new StringBuilder(); 
    Cursor messagesCursor = cr.query(uri, new String[] { "_id","address","body","person"}, null,null, null);
    smsBackup.append("SMS Back UP (Total Message(s)::"+messagesCursor.getCount()+") \n\n");

    String name = null;
    if(messagesCursor.getCount() > 0){
        while(messagesCursor.moveToNext()){
            name = null;
            name = getName(messagesCursor.getString(messagesCursor.getColumnIndex("address")));

            if(name==null)
                name = "Sender : " + messagesCursor.getString(messagesCursor.getColumnIndex("address"));

            smsBackup.append("Sender : "+name +"\n"+  "Message : "+messagesCursor.getString(messagesCursor.getColumnIndex("body")) + "\n\n");
        }
    }
 messagesCursor.close();
}catch(IOException e){
//handle here, if not log it
}finally{
//can also close here if you want, need to wrap in another try block and check for null
}

Seems like the problem is the ioexception is being caught before the close() could be called. The method is then thrown at that point and is never called. I could be wrong, I just took a quick glance at it. I hope this helps.


Looking for: ['mfix==25.1.2', 'mfix-solver=25.1.2'] warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/497deca9.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/09cdf8bf.json" was modified by another program warning libmamba Could not parse mod/etag header warning libmamba Could not parse mod/etag header warning libmamba Could not parse mod/etag header warning libmamba Could not parse mod/etag header warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/47929eba.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/3e39a7aa.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/2ce54b42.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/4ea078d6.json" was modified by another program https://mirrors.ustc.edu.cn/anaconda/cloud/menpo.. https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18.. https://mirrors.ustc.edu.cn/anaconda/cloud/bioco.. https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18.. https://mirrors.ustc.edu.cn/anaconda/pkgs/main/n.. https://mirrors.aliyun.com/pypi/simple/linux-64 0.4s https://mirrors.ustc.edu.cn/anaconda/pkgs/main/l.. 17.6s https://mirrors.ustc.edu.cn/anaconda/cloud/msys2.. https://mirrors.aliyun.com/pypi/simple/noarch 0.6s Multi-download failed. Reason: Transfer finalized, status: 404 [https://mirrors.aliyun.com/pypi/simple/noarch/repodata.json] 2318 bytes # >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<< Traceback (most recent call last): File "/home/ps/miniforge3/lib/python3.10/site-packages/conda/exceptions.py", line 1132, in __call__ return func(*args, **kwargs) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 941, in exception_converter raise e File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 934, in exception_converter exit_code = _wrapped_main(*args, **kwargs) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 892, in _wrapped_main result = do_call(parsed_args, p) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 758, in do_call exit_code = create(args, parser) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 632, in create return install(args, parser, "create") File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 499, in install index = load_channels(pool, channels, repos) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/utils.py", line 129, in load_channels index = get_index( File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/utils.py", line 110, in get_index is_downloaded = dlist.download(api.MAMBA_DOWNLOAD_FAILFAST) RuntimeError: Multi-download failed. Reason: Transfer finalized, status: 404 [https://mirrors.aliyun.com/pypi/simple/noarch/repodata.json] 2318 bytes `$ /home/ps/miniforge3/bin/mamba create -n mfix-25.1.2 mfix==25.1.2 mfix-solver=25.1.2 -c conda-forge -c https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18d1e8d1637bad33e96216d6//conda/dist` environment variables: CIO_TEST=<not set> CONDA_DEFAULT_ENV=base CONDA_EXE=/home/ps/miniforge3/bin/conda CONDA_PREFIX=/home/ps/miniforge3 CONDA_PROMPT_MODIFIER=(base) CONDA_PYTHON_EXE=/home/ps/miniforge3/bin/python CONDA_ROOT=/home/ps/miniforge3 CONDA_SHLVL=1 CURL_CA_BUNDLE=<not set> LD_LIBRARY_PATH=/usr/local/cuda-12.0/lib64: LD_PRELOAD=<not set> PATH=/home/ps/miniforge3/bin:/home/ps/miniforge3/condabin:/home/ps/.local/b in:/home/ps/bin:/usr/local/cuda- 12.0/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin REQUESTS_CA_BUNDLE=<not set> SSL_CERT_FILE=<not set> WINDOWPATH=2 active environment : base active env location : /home/ps/miniforge3 shell level : 1 user config file : /home/ps/.condarc populated config files : /home/ps/miniforge3/.condarc /home/ps/.condarc conda version : 23.3.1 conda-build version : not installed python version : 3.10.12.final.0 virtual packages : __archspec=1=x86_64 __cuda=12.2=0 __glibc=2.28=0 __linux=4.18.0=0 __unix=0=0 base environment : /home/ps/miniforge3 (writable) conda av data dir : /home/ps/miniforge3/etc/conda conda av metadata url : None channel URLs : https://conda.anaconda.org/conda-forge/linux-64 https://conda.anaconda.org/conda-forge/noarch https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18d1e8d1637bad33e96216d6//conda/dist/linux-64 https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18d1e8d1637bad33e96216d6//conda/dist/noarch http://pypi.douban.com/simple/linux-64 http://pypi.douban.com/simple/noarch https://mirrors.aliyun.com/pypi/simple/linux-64 https://mirrors.aliyun.com/pypi/simple/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch https://mirrors.ustc.edu.cn/anaconda/pkgs/free/linux-64 https://mirrors.ustc.edu.cn/anaconda/pkgs/free/noarch https://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64 https://mirrors.ustc.edu.cn/anaconda/pkgs/main/noarch https://repo.anaconda.com/pkgs/main/linux-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /home/ps/miniforge3/pkgs /home/ps/.conda/pkgs envs directories : /home/ps/miniforge3/envs /home/ps/.conda/envs platform : linux-64 user-agent : conda/23.3.1 requests/2.31.0 CPython/3.10.12 Linux/4.18.0-348.el8.x86_64 centos/8.5.2111 glibc/2.28 UID:GID : 1000:1000 netrc file : None offline mode : False An unexpected error has occurred. Conda has prepared the above report.
最新发布
07-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值