不能在Android的调用String.isEmpty()能在、Android、isEmpty、String

2023-09-04 09:14:52 作者:晴天里的小幸福

在我的Andr​​oid应用程序,我不能使用的 String.isEmpty()的功能,这是坐落在JDK 1.6。 Android 2.1的lib中没有此功能java.lang.String中类

我试着输入JRE系统库到我的项目,因为它有这个功能,但没有效果。

我该如何解决这个问题,让我的应用程序使用此功能?

解决方案   

我该如何解决这个问题,让我的应用程序使用此功能?

您不能。

主函数中调用这个方法,该方法能判断通过形参获得的字符串是否符合身份证基本要求

使用 string.length减()== 0 代替。它是向后兼容所有的方式回到JDK 1.0 ... ...和J2ME为好。

String.equals()是另一种选择。

  

您肯定是没有办法来配置Eclipse来投入code类的明确的图书馆?

如果你希望你的应用程序,以一个的真正的Andr​​oid设备上运行没有。的Java / Android的平台故意让你很难鼓捣核心类库的行为。一开始,你只能做它通过修改Davlik相当于BOOTCLASSPATH或的rt.jar 的文件,并没有这些可以运行的JVM内完成。

那种修修补补具有的危险的潜在破坏Java的其他应用程序。即使假设你不能妥协,恶意调整到(共享)的Java核心类仍然可以潜在地允许一个应用程序的干扰,或从其他应用程序窃取信息(因为下面提到的过程/ UID分离)直接Android应用程序分离

In my android application I can't use String.isEmpty() function which is situated in JDK 1.6. Android 2.1 lib doesn't have this function in java.lang.String class

I tried to input JRE System library to my project, because it has this function, but there was no effects.

How can I solve this problem and allow my application to use this function?

解决方案

How can I solve this problem and allow my application to use this function?

You can't.

Use String.length() == 0 instead. It is backwards compatible all the way back to JDK 1.0 ... and with J2ME as well.

String.equals("") is another alternative.

Are you sure that there is no way to configure Eclipse to put into a code classes from definite libraries?

Not if you want your app to run on a real Android device. Java / Android platforms intentionally make it hard for you to tinker with the behaviour of the core class libraries. For a start, you can only do it by modifying the Davlik equivalent of the bootclasspath or rt.jar file, and neither of these can be done within a running JVM.

That kind of tinkering has the risk of potentially breaking Java for other apps. Even assuming that you can't compromise Android app separation directly (because of the process/uid separation mentioned below), malicious tweaks to the (shared) Java core classes could still potentially allow one app to interfere with, or steal information from another app.

 
精彩推荐
图片推荐