Gluon on iPhone says NoSuchMethodError

Following:

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

      

it runs on desktop, but not deployed on mobile devices.

Thanks for any suggestion ..

+1


source to share


1 answer


Most of the class java.util.Date

runs on mobile devices (Android and iOS). However, there are a few cases that are not available.

On Android or iOS, if you try

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

      

which is referring to Java 8 static method Date.from(Instant)

, you will 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 problem, you can instead use the regular constructor, which in turn uses a static method:

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

      

Alternatively, you can use the new package java.time

.

+2


source







All Articles