iPhone上的Gluon告诉NoSuchMethodError [英] Gluon on iPhone telling NoSuchMethodError

查看:132
本文介绍了iPhone上的Gluon告诉NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下一件事:

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

它运行在桌面上,但未部署在移动设备上.

its running on desktop but not deployed on mobile..

感谢您的任何建议.

推荐答案

大多数 java.util.Date 类均可在移动设备(Android和iOS)上使用.但是,有些情况不可用.

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

如果您尝试在Android或iOS上

On Android or iOS if you try

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

引用Java 8静态方法 Date.from(Instant)

,您将得到提到的异常:

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()));

或者,您可以使用新的 java.time 包.

Alternatively you can use the new java.time package.

这篇关于iPhone上的Gluon告诉NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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