Ehtasham Ali
Ehtasham Ali

Reputation: 75

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

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.

Upvotes: 1

Views: 2797

Answers (3)

karishma
karishma

Reputation: 1

java.util.Date date=new java.util.Date(); try this ,it will works.

Upvotes: 0

Xpacer
Xpacer

Reputation: 41

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

Upvotes: 0

Skizo-ozᴉʞS ツ
Skizo-ozᴉʞS ツ

Reputation: 20646

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.

enter image description here

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

Upvotes: 0

Related Questions