Gluon on iPhone telling NoSuchMethodError

2019-07-27 04:14发布

Next thing:

java.lang.NoSuchMethodError: 
java.util.Date.from(Ljava/time/Instant;)Ljava/util/Date;

its running on desktop but not deployed on mobile..

Thanks for any suggestion..

1条回答
虎瘦雄心在
2楼-- · 2019-07-27 05:08

Most of the java.util.Date class works on mobile (Android and iOS). However there a few cases that are not available.

On Android or iOS if you try

Date date = Date.from(Instant.now());

that refers to the Java 8 static method Date.from(Instant), you'll get the exception you mentioned:

W System.err: Caused by: java.lang.NoSuchMethodError: No static method from(Ljava/time/Instant;)Ljava/util/Date; in class Ljava/util/Date; or its super classes (declaration of 'java.util.Date' appears in /system/framework/core-oj.jar)

To solve this issue, you can use the usual constructor instead, which is in turn what the static method uses:

// Android, iOS
Date date = new Date(Instant.now().toEpochMilli()));

Alternatively you can use the new java.time package.

查看更多
登录 后发表回答