I can't import java.util.date in activity

半世苍凉 提交于 2020-01-16 04:17:19

问题


In my project I need to to use current date and time. For this I'm importing java.util.Date. This import is working fine few hours ago. But I have an error in R file ( r cannot resolve ) and this error is because of some xml mistake. When I resolved that issue and sync project again that error is gone. But after that I cannot able to import (java.util.Date , java.util.Calendar) in any of my project.

I tried to import this in my newly created project. But still not found java.util.Date. Even in my old projects where this import is working fine few days ago. Currently it is not working and showing red.

import java.util.Calendar;

import java.util.Date;

Date and Calendar are showing in red.

Date d=new Date();

SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");

Above Date and SimpleDateFormat are showing in red. And when I hover over there and press (control+alt) IDE will give option to import java.sql.Date not java.util.Date.


回答1:


Sometimes Android studio goes crazy, and it's good to do a Clean project, so I recommend you to do this. I know you did it, but after that, you can Rebuild the project and then close completely Android Studio.

If it does not work just type here on Invalidate cache /restart as shown on the screenshot.

Doing this, it should work, if it does not, make sure your SDK is imported correctly.




回答2:


I had this issue one time with java.util.calendar. Invalidating Cache/Restart worked for me.



来源:https://stackoverflow.com/questions/56327718/i-cant-import-java-util-date-in-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!