草庐IT

getResource

全部标签

Java 9.0 |类加载器::getResourceAsStream: NullPointerException

下面这段代码,我从“/resource”文件夹中的文件夹中获取我的文件,在Java8中对我来说工作正常://e.gfileName="folder0/file1.extension2"ClassLoaderclassLoader=ResourceLoader.class.getClassLoader();InputStreamin=classLoader.getResourceAsStream(fileName);Scannerscanner=newScanner(in,"UTF-8");在Java9中它不会,classLoader.getResourceAsStream(fileNa

java - getClass().getResource() 总是返回 null

我正在尝试在我的src文件夹中设置位于我的资源文件夹中的图像的URL。它总是将URL设置为空。图像在那里,一切都被正确命名。问题是什么?谢谢!我的文件结构:sp1来源资源01.png这是我尝试设置图片URL的代码:this.setImagePath(getClass().getResource("/resources/01.png"));setImagePath正在执行此操作,我确定这不是问题所在,因为我跟踪了执行并将其设置为null。publicfinalvoidsetImagePath(URLimagePath){this.imagePath=imagePath;}解决方案我必须清

java - getResource() 在 Gradle 项目中返回 null

我知道关于这个还有其他几个问题......Class.getResource()returnsnullJava-class.getResourcereturnsnullCallingcontext.getResources()returnsnullgetClassLoader().getResource(filepath)returnsanullpointer但我的问题似乎有点不同,因为我似乎拥有所有必要的东西来避免这个问题。代码:this.getClass().getResource("checkstyle_whitespace.xml");//null问题是我已经通过检查调试器中的

android - 在 Android 中使用 ClassLoader 动态加载类作为字节数组

我正在尝试将一个类作为字节数组加载,这样我就可以通过网络发送它并通过反射远程执行它。这个类(在本例中为Bubble)在同一个包中。问题是我无法使用getResourceAsStream(classpath)方法获取资源。.getResourceAsStream(classpath)总是返回null。我已经在J​​ava项目中测试了这段代码并且工作正常。我认为问题出在资源路径上,Android是否加载.class文件?privatevoiddoSomething(){Bubbleb=newBubble();try{//Trytoretrievetheclassbytearraybyte[

java - getResources 返回 null

我们注册一个广播接收器来接收包安装或卸载事件。但是一些用户报告崩溃报告是这样的:java.lang.RuntimeException:Unabletocreateapplicationcom.kc.security.MoSecurityApplication:java.lang.RuntimeException:getResourcesisnull:dir-/data/app/com.cm.mg-1.apk,srcVal-1,srcVal-2atandroid.app.LoadedApk.makeApplication(LoadedApk.java:495)atandroid.app.

来自非 Activity 类的非 Activity 类中的Android getResource?

我在非Activity类中获得了以下方法,我的代码如下。publicclassReadTextByLineNo{publicvoidsetContext(Context_context){if(context==null){context=_context;}}publicStringgetTextByLine(intFilename,intLineNumber){Stringoutput="";Stringline="";intcounter=1;try{InputStreamin=context.getResources().openRawResource(Filename);//

android.content.res.Resources android.content.Context.getResources()' 在空对象引用上

我试图在我的SlidingTabLayout上显示图标,所以在我的适配器中我创建了这样的东西,我在寻找教程的某个时候找到了它我编辑了你将使用getDrawable的部分,因为它说它已经弃用并应用我找到的解决方案@OverridepublicCharSequencegetPageTitle(intposition){Drawableimage=ResourcesCompat.getDrawable(mContext.getResources(),icons[position],null);image.setBounds(0,0,48,48);SpannableStringsb=newSp

android - 使用 Locale.getDefault() 和 context.getResources().getConfiguration().locale 的语言环境有什么区别?

返回的字符串有什么区别吗:Locale.getDefault().toString()和context.getResources().getConfiguration().locale.toString()询问是因为我怀疑这会导致应用程序中出现错误,在使用Locale.getDefault().toString()之前有效的功能不再适用于context.getResources()。getConfiguration().locale.toString(),在某些美国设备上。但不确定是否是这个原因。谢谢! 最佳答案 Locale.ge

java - Class.getResource(className) 给我 NullPointerException

我制作了一个独立于平台的库,我想在J2SE和Android项目上使用它。在这个库中,我有一个Version类,它从list中加载其版本详细信息。在PC上这很好用,在Android上我得到一个NullPointerException,我不知道为什么。这是我的课:publicclassVersion{privatestaticintAPPCODE=12354;privatestaticintMAJOR;privatestaticintMINOR;privatestaticcharRELEASE;privatestaticintBUILD;privatestaticintPROTOCOL;s

android - 使用 Context.getText 和 Context.getResources.getText 有什么区别吗?

所以我注意到似乎有两种方法可以获取相同的数据,我不确定是否有关于何时应该使用其中任何一种的指南(除了绕过getResources可以节省内存,如果你实际上不想多次使用该对象)。但除此之外,我想知道是否有使用指南或理由Context.getText(id)与Context.getResources.getText(id)有人能帮忙吗? 最佳答案 没有区别。getText(id)的来源是:/***Returnalocalized,styledCharSequencefromtheapplication'spackage's*defaul