Unresolved reference: RecyclerView when trying to inherit Adapter - android

I am trying to make a RecyclerView in Android Studio and I am struggling to inherit from RecyclerView.Adapter<>()
This is the fragment of code that contains the problem:
package Adapters
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.R
import android.os.Bundle
import models.Post
class PostAdapter(private val postList: List<Post>, private val content: String) : RecyclerView.Adapter<PostAdapter.PostViewHolder>() {
Android Studio sets "RecyclerView" red and I can't get rid of it. I tried solutions from other posts on stackoverflow, tried to follow tutorials on the internet, but there isn't anything about androidx and I can't use older version (android.support.v7.widget.RecyclerView), because Android Studio won't let me.
I imported RecyclerView in mains build.gradle:
implementation "androidx.recyclerview:recyclerview:1.1.0"
And added google() in the highest-instance build.gradle
I hope I explained the problem properly and you can help me.

I think you are missing import of recycler view
import androidx.recyclerview.widget.RecyclerView
Also If you've just migrated to Android X Android studio might be buggy so you want to do File -> Invalidate Caches/Restart

SOLVED!
Did you remember to specify an id for the recyclerview after adding it to your main activity? If yes, then check to make sure that the id you gave is exactly the same as the red text that's causing an unresolved error. Eg
If in main_activity.xml you have
`<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />`
Then in MainActivity.kt you should have
`recyclerView.layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)`
The word "recyclerView" should be exactly the same in the 2 files where it is used

In my case, I was using the wrong library version.
My library version was way too greater than the released version.
implementation 'androidx.recyclerview:recyclerview:2.9.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'

Related

androidx.compose.ui.tooling.preview.PreviewActivity is not an activity subclass or alias

I updated my compose and kotlinCompilerExtensionVersion to 1.0.0-rc02 from beta09, Kotlin version to 1.5.21, Gradle version to 7.1 and Gradle plugin version to 7.1.0-alpha04
Ever since - on trying to run MyScreen - I'm getting this error:
androidx.compose.ui.tooling.preview.PreviewActivity is not an activity
subclass or alias
I am not able to resolve this. How do I resolve this?
I am using Compose 1.0, Kotlin 1.5.10 and Android Studio 2020.3.1, and I run into the same problem on most of my previews (not on others).
On the top bar menu, clicking on "Edit configurations" and manually creating a new configuration with the same parameters as those in the invalid configuration with warning (" androidx.compose.ui.tooling.PreviewActivity is not an Activity subclass or alias") did the trick for me.
I'm experiencing this error using Bumblebee (AKA, 2021.1.1) Canary 6, 7, and 8, using compose version 1.0.0, 1.0.1, and 1.1.0-alpha01. I've just raised a bug on the Studio issue tracker:
https://issuetracker.google.com/issues/196248459
To quote myself:
It seems clear this is a "left hand doesn't know what right hand is doing" thing, because PreviewActivity is not in that package, but rather androidx.compose.ui.tooling – it hasn't been in android.compose.ui.tooling.preview since compose 1.0.0-beta09.
UPDATE
I was able to get previews working again by clearing off all the preview run configurations. Here were my steps:
Click on the "run configurations" selector and select Edit Configurations...
Expand the Compose Preview grouping
Select all the preview configurations (you can select the first and shift-select the last)
Click the - button to remove all the collections
Click Ok
Run Invalidate Caches... in the file menu
After AS restarts and your cache repopulates, run a preview. It should work now.
Apparently AS was caching "junk" in the temporary run configurations it was creating every time I launched a preview. The "junk" was valid for earlier versions of AS, but broke later versions. Clearing out this cache got me working again.
I've got the same error with Compose 1.0.0 and Kotlin 1.5.10 (which is recommended).
I fixed these with adding the following dependence debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" in my gradle file.
Don't forget to set the version of the dependence to your current compose version.
After a rebuild and reload of the preview everything works fine for me.
The Preview of the example looks like this:
package com.example.compose.basics.ui
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import de.db.dbs.travio.compose.basics.themeing.ComposeBasicsTheme
#Preview
#Composable
fun ScreenContent() {
ComposeBasicsTheme {
Card(modifier = Modifier
.padding(8.dp)
.shadow(8.dp, RoundedCornerShape(32.dp))
) {
Text(
text = "Hello World!",
modifier = Modifier.padding(16.dp)
)
}
}
}
The thing that worked for me was downgrading the ui-tooling version to beta09, i.e using this dependency for ui-tooling:
implementation "androidx.compose.ui:ui-tooling:1.0.0-beta09"
Updating the compose_version to 1.0.1 , and kotlin-gradle-plugin to 1.5.21 fixes the issue if the versions used are lower than mentioned here.

how to solve: Bundle' is deprecated. Use Android KTX version?

I am trying to pass data between fragments using navigation controller. in this documentation: https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data
it is said that I can send data using bundle, but when I type the code below:
var bundle = bundleOf("amount" to amount)
view.findNavController().navigate(R.id.confirmationAction, bundle)
I have a message: Bundle' is deprecated. Use Android KTX version ?
what should I do ? I don't understand about that 'Use the Android KTX version'
I finally find the answer,
so first add dependecy:
dependencies {
implementation 'androidx.core:core-ktx:1.0.0'
}
then import this:
import androidx.core.os.bundleOf
and finally the warning will dissapear
I think it's requesting that top level function: https://developer.android.com/reference/kotlin/androidx/core/os/package-summary#bundleOf%28kotlin.Pair%29
The import line should be something like: import androidx.core.os.bundleOf

android.annotation cannot be resolved IntDef and NonNull

I'm trying to run a sample android code in Andriod Studio, but when I try:
import android.annotation.IntDef;
import android.annotation.NonNull;
keep getting an error related to this line like:
the import android.annotation cannot be resolved
Any suggestion will be appreciated
I think it would be better if you work with the support annotations:
add this dependency to your project and see if it works:
compile 'com.android.support:support-annotations:24.2.0'
accourding to this answer you can use
android-sdk/tools/support/annotations.jar - Which includes the following annotations:
SuppressLint
TargetApi
android-sdk/extras/android/support/annotations/annotations.jar - Which includes many other annotations:
AnimRes
AnimatorRes
AnyRes
ArrayRes
AttrRes
BoolRes
ColorRes
DimenRes
DrawableRes
FractionRes
IdRes
IntDef
IntegerRes
InterpolatorRes
LayoutRes
MenuRes
NonNull
Nullable
PluralsRes
RawRes
StringDef
StringRes
StyleRes
StyleableRes
XmlRes
I had faced the same problem and came across this question but was not answered.
I could resolve this issue by following steps mentioned here.
After this, You shall sync the project with Gradle files.
Note: You may not find the same annotation path
e.g. import android.annotation.NonNull; --> import androidx.annotation.Nullable;

Android Databinding : package does not exist

I'm trying to use data-binding with Android.
I can not anymore build my project. I got this error :
"Error:(13, 46) error: package ch.company.project.databinding does not
exist"
Here my gradle :
http://pastebin.com/dkXd1Mxr
and
http://pastebin.com/n9hkFWGQ
And here the gradle output :
https://pastebin.com/w93Rausg
Thanks to Yigit!
The issue was not directly link to Android Databinding.
There were a bug in the project (some variables not correctly setted)
I would recommend to use gradle with "--debug and --stacktrace" for more informations, it's helping a lot.
earlier my package name was "com.xyz.abc.Models"
changing the package name to all small letters "Models" -> "models"
solved the issue.
The bug is not the DataBinding Package, it's a syntactic or logical error. For example, you have the attribute "lastName" in your POJO, but in the layout it's android:text="#{user.lastname}".
Check your "layout" and do Rebuild Project.
I am not satisfied with accepted answer, that tell you to stack trace without hints.
Here are some possible causes that lead to this problem. Check if you are not doing any of the following.
Basically Android DataBinding is not that mature still. It will fail without appropriate errors many times.
So if you have an issue like package ch.company.project.databinding does not exist".
Possible causes of fail:
First of all check your recently edited layouts xml one by one for errors (for wrong imports & variables). I don't get proper error in this case usually.
Check your data binding syntax in binding block ({...}) in layout element for errors. Always Rebuild (not Build) project after working in one layout.
Check your #BindingAdapter method having correct parameters. For example imageUrl binding adapter would accept ImageView or View as first parameter.
You should always Rebuild project after doing work in one layout.
If you are not able to find errors by above steps, then try --debug and --stacktrace in compile option of
File> Settings> Build, Execution, Deployment> Compiler> Command-line Options
Make sure your package name start with lowercase letter.
in my case issue solved after two hours of struggle
Package name should start with small letter.
for example Activities is wrong it'll give an error instead refactor->rename to activities
I got the error:
Error:(9, 46) error: package com.company.www.bar.databinding does not
exist.
i just remove "=" sign . it worked for me
From this :
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="#={()->activity.onButtonClick()}"/>
to :
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="#{()->activity.onButtonClick()}"/>
I had similar problems with my project
You could try:
check xml files for errors that cause a build failure
clean project
File -- invalidate caches / restart
On my particular case, I was using Dagger 2. This package error appears in a lot of classes without any relation with the original error: a dependency injection error.
Happy reminder: Scroll more on your stacktrace to know what is the real problem.
I was stuck with same error for hours. After trying several solution from stackoverflow, I updated my project with stable gradle dependencies.
Still it was not solved, however with the same gradle dependency DataBinding was working fine in another project of mine.
So, I went project folder using explorer and Deleted 2 things.
build folder
all files from .idea/libraries
After that i synced the project and it continued to work just fine.
Package names have to START with Small Letters. Otherwise, Binding library cannot understand that is it class or package. Moreover, you do NOT need to do all of it with small letters.
Example, wrong usage:
package com.thecompany.activity.ContactInfo; //Problem is ContactInfo, 'C'.
Example, TRUE usage:
package com.thecompany.activity.contactInfo; //Solution is contactInfo, 'c'.
Make sure your model's fields you reference in layout have public access modifiers
Change
{ databinding = true}
to
buildFeatures{
dataBinding = true
}
If you're coming to this question because you switched to JDK11 in Android Studio Artic Fox and your view binding broke in the UI but not during execution then be aware that this is a known issue and should be resolved in Bumble Bee:
https://issuetracker.google.com/issues/180946610
The current fix is to switch back to JDK8 (or install the Bumble Bee canary release).
To get rid of this error just enclose your complete layout design inside a plain layout tag in the activity_main.xml file.
After wasting many hours in finding solution this worked for me. Give it a try.
if you tried this steps
invalidate/restart`
keeping this properties in gradel.properties
android.databinding.enableV2=false
android.enableExperimentalFeatureDatabinding=true
and checking all xml files looks good.
then you should go with this solution, add below code in project level build.gradle
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "1000"
}
}
}
this will give you exact error where you have actual error
explanation: above code will increase the size of the compile error
in my case, i follow the android documentation :
buildFeatures {
viewBinding true
}
use "=" instead of space
buildFeatures {
viewBinding = true
}
Try following Refactor -> migrate to androidx
and in the build.grade(:app)
implementation 'androidx.appcompat:appcompat:1.0.0'
or use new version is released
implementation 'androidx.databinding:databinding-runtime:4.1.0'
Make sure that if your layout filename is named in the following format: <name>_activity.xml that your binding class name complies the following format as well: <name>ActivityBinding
For me, changing my layout filename from activity_login.xml to login_activity.xml resolved this issue because my binding class name was LoginActivityBinding.
Here's an except from the Android Layouts and binding expressions page mentioning this:
A binding class is generated for each layout file. By default, the name of the class is based on the name of the layout file, converting it to Pascal case and adding the Binding suffix to it. The above layout filename is activity_main.xml so the corresponding generated class is ActivityMainBinding
if you use a model in your layout, make sure you dont have the model and the package named same and also the paackage name should start with small letter.
i changed mine from Model>Model.class to modelPac>Model.class
In my case the problem appeared when I was creating productFlavors and set sourceSets.
Changing
sourceSets {
develop {
res.srcDirs = ['myApp/src/develop/res']
}
to
sourceSets {
develop {
res.srcDirs = ['src/develop/res']
}
}
solved my issue.

Using Arcanimator in android app

Hi i want to use ArcAnimator and ArcLayout in one android project .
for that i using this dependencys
compile 'com.ogaclejapan.arclayout:library:1.0.1#aar'
compile 'com.github.asyl.animation:arcanimator:1.0.0'
but i give this error message
cannot resolve symbol'SupportAnimator'
cannot resolve symbol'ViewAnimationUtils'
in import line
import io.codetail.animation.SupportAnimator;
import io.codetail.animation.ViewAnimationUtils;
and its strange because i do not give this error in this lines
import io.codetail.animation.arcanimator.ArcAnimator;
import io.codetail.animation.arcanimator.Side;
which is in same library.
can anyone help me about that?
You have to use other dependency to use Support Animator say https://github.com/kedzie/Support_v4_NineOldAndroids. Support Animator is not there in the package of the library that you have used. It’s not showing inside the package you have used, you can check at https://github.com/asyl/ArcAnimator/tree/master/animator/src/main/java/io/codetail/animation/arcanimator.
Also you can take help of some samples given here at https://github.com/ozodrukh/CircularReveal/releases.

Categories

Resources