Home > Back-end >  Android Studio: Import not being recognized
Android Studio: Import not being recognized

Time:01-31

I'm having an issue where I've imported an import in order for a piece of code to work but no matter how many times I import the import, the code isn't recognizing that it's there. I've already tried invalidating and restarting, multiple times. I've read that another solution to this is to Sync with File System, but I don't appear to have that option under File.

The import in question is import java.text.MessageFormat.format

import android.content.ContentValues.TAG
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import com.squareup.okhttp.internal.http.HttpDate.format
import java.math.BigDecimal
import java.sql.Time
import java.sql.Timestamp
import java.text.DateFormat
import java.text.MessageFormat.format
import java.util.*
import kotlin.collections.ArrayList

class RemindersActivity : AppCompatActivity() {

lateinit var petID: String
val db = Firebase.firestore
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_reminders)
    displayReminders()

    petID = intent.getStringExtra("petID").toString()

    val fab: View = findViewById(R.id.fab_reminders)
    fab.setOnClickListener {
        val intent = Intent(this, AddReminderActivity::class.java)
        intent.putExtra("petID", petID)
        startActivity(intent)
    }
}

override fun onStart() {
    super.onStart()
    displayReminders()
}

private fun displayReminders() {
    val recyclerview = findViewById<RecyclerView>(R.id.recyclerview_reminders)

    recyclerview.layoutManager = LinearLayoutManager(this)

    db.collection("pets").document(petID).collection("reminders").get().addOnSuccessListener { result ->
        val data = mutableListOf<RemindersData>()
        for (document in result) {
            val title = document.data["title"].toString()
            val timestamp = document.data["timestamp"] as Long
            val cal = Calendar.getInstance()
            cal.timeInMillis = timestamp * 1000L
            val date = DateFormat.format("dd-MM-yyyy hh:mm:ss aa", cal).toString() //<- code note recognizing import is format
            val frequency = document.data["frequency"].toString()

            data.add(RemindersData(title, date, frequency))
        }
        val adapter = RemindersAdapter(data)

        recyclerview.adapter = adapter
    }.addOnFailureListener {  e->
        Log.w(TAG, "Error getting documents", e)
    }


}

}

CodePudding user response:

It just seems that you have added a few imports from the java packages instead of the android packages. It can happen when you use auto import in the IDE and there are multiple options and you click the wrong one. When that happens you either have to undo the import or fix it manually.

Remove the import for

import java.text.DateFormat

Add the import for

import android.text.format.DateFormat

Afterwards, if there are any unused imports left, you can remove those as well.

  •  Tags:  
  • Related