无法解决 android studio 中的符号“java.time.LocalDate”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28745205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cannot resolve symbol 'java.time.LocalDate' error in android studio
提问by siim sammul
I am trying to use java.time.LocalDate in my android app, however if I try to import it, then any class from java.time gives a cannot resolve symbol error in Android studio 1.1
我正在尝试在我的 android 应用程序中使用 java.time.LocalDate,但是如果我尝试导入它,那么 java.time 中的任何类都会在 Android studio 1.1 中给出无法解析的符号错误
The only reason I could figure out for this is that it doesn't support java 8. Is that really the case?
我能弄清楚的唯一原因是它不支持 java 8。真的是这样吗?
回答by Basil Bourque
Android API level 26
安卓 API 级别 26
Android API level 26 gained an implementation of java.timeincluding your LocalDate
class.
Android API 级别 26 获得了java.time的实现,包括您的LocalDate
类。
Earlier Android
早期的安卓
For Android <26, alternatives include:
对于 Android <26,替代方案包括:
- ThreeTen-Backportis a back-port of much of the java.time functionality to Java 6 & 7.
- ThreeTenABPadapts ThreeTen-Backport to Android.
- Joda-Timeis commonly used in Android projects. Joda-Time inspired the java.time package in Java 8, but they are not drop-in replacements. The Joda-Time team advises migration to java.time.
- ThreeTen-Backport 是 Java 6 和 7 的大部分 java.time 功能的后向端口。
- ThreeTenABP将 ThreeTen- Backport适配到 Android。
- Joda-Time常用于 Android 项目。Joda-Time 启发了 Java 8 中的 java.time 包,但它们不是直接替代品。Joda-Time 团队建议迁移到 java.time。
About java.time
关于java.time
The java.timeframework is built into Java 8 and later. These classes supplant the troublesome old legacydate-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
该java.time框架是建立在Java 8和更高版本。这些类取代了麻烦的旧的遗留日期时间类,例如java.util.Date
, Calendar
, & SimpleDateFormat
。
The Joda-Timeproject, now in maintenance mode, advises migration to the java.timeclasses.
现在处于维护模式的Joda-Time项目建议迁移到java.time类。
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
要了解更多信息,请参阅Oracle 教程。并在 Stack Overflow 上搜索许多示例和解释。规范是JSR 310。
You may exchange java.timeobjects directly with your database. Use a JDBC drivercompliant with JDBC 4.2or later. No need for strings, no need for java.sql.*
classes.
您可以直接与数据库交换java.time对象。使用符合JDBC 4.2或更高版本的JDBC 驱动程序。不需要字符串,不需要类。java.sql.*
Where to obtain the java.time classes?
从哪里获得 java.time 类?
- Java SE 8, Java SE 9, Java SE 10, and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6and Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- Later versions of Android bundle implementations of the java.time classes.
- For earlier Android (<26), the ThreeTenABPproject adapts ThreeTen-Backport(mentioned above). See How to use ThreeTenABP….
- Java SE 8、Java SE 9、Java SE 10及更高版本
- 内置。
- 具有捆绑实现的标准 Java API 的一部分。
- Java 9 添加了一些小功能和修复。
- Java SE 6和Java SE 7
- 多的java.time功能后移植到Java 6和7在ThreeTen-反向移植。
- 安卓
- 更高版本的 Android 捆绑实现 java.time 类。
- 对于早期的 Android(<26),ThreeTenABP项目采用了ThreeTen-Backport(上面提到过)。请参阅如何使用ThreeTenABP ...。
回答by Meno Hochschild
Yes, Android does not support Java-8. And about the new date/time-API contained in Java-8, you can look at this issue:
是的,Android 不支持 Java-8。关于 Java-8 中包含的新日期/时间 API,你可以看看这个问题:
http://code.google.com/p/android/issues/detail?id=62192
http://code.google.com/p/android/issues/detail?id=62192
Currently there are no plans to introduce JSR-310 (java.time-package) in Google Android.
目前没有计划在 Google Android 中引入 JSR-310 (java.time-package)。
回答by Mara
Finally date/time-API contained in Java 8 is added to Android API level 26 which was recently released.
最后,Java 8 中包含的日期/时间 API 被添加到最近发布的 Android API 级别 26。