gpt4 book ai didi

android - Resources.getSystem().openRawResource 给出资源未找到异常

转载 作者:太空狗 更新时间:2023-10-29 16:19:10 25 4
gpt4 key购买 nike

在我的 android 应用程序中,我想以静态方法访问我的文本文件,但使用以下代码:

InputStream = Resources.getSystem().openRawResource(R.raw.adv_types);

给我运行时异常:找不到资源异常

虽然我可以使用此代码以非静态方法访问文件:

InputStream = getResources().openRawResource(R.raw.adv_types);

虽然它在静态方法中不可用。

您知道为什么第一个代码不起作用吗?在静态方法中访问文本文件(或一般资源)的解决方案是什么?

最佳答案

因为 Resources.getSystem() 只允许您访问系统资源而不是应用程序资源。来自文档:

Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).

关于android - Resources.getSystem().openRawResource 给出资源未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19733398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com