getClass().getProtectionDomain().getCodeSource().getLocation().getPath()抛出空指针异常 [英] getClass().getProtectionDomain().getCodeSource().getLocation().getPath() Throw a null pointer exception

查看:69
本文介绍了getClass().getProtectionDomain().getCodeSource().getLocation().getPath()抛出空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java类中使用此行代码来检索用于自定义ClassLoader的URI:

I used this line of code in a Java class to retrieve a URI which i used to customize the ClassLoader:

String uri = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();

现在要准确地在MainActivity的Android应用中使用同一行代码抛出空指针异常.

Now the same line of code in an Android App in the MainActivity to be exact throw a null pointer exception.

Android开发是否有一些特别的东西?谢谢.

Is there something special for Android development ? Thanks.

推荐答案

getProtectionDomain()未在Android的Java版本中实现

getProtectionDomain() is not implemented in Android's version of Java

http://developer.android.com/reference/java/lang/Class.html#getProtectionDomain%28%29

此外, ProtectionDomain 类被标记为旧版安全代码;请勿使用."

Also, the ProtectionDomain class is marked as "Legacy security code; do not use."

http://developer.android.com/reference/java/security/ProtectionDomain.html

我认为这仅存在于Android Java中以保持编译兼容性.

I assume this only exists in Android Java to maintain compilation compatibility.

这篇关于getClass().getProtectionDomain().getCodeSource().getLocation().getPath()抛出空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆