Kotlin messing with java functions? - java

Everything was working very well until I update android studio.
I am using java to develop my app but now when I try to compile I get this error:
MainActivity.java:47: error: cannot access Function1
bottomNav.setOnItemSelectedListener(new OnItemSelectedListener() {
^
class file for kotlin.jvm.functions.Function1 not found
I don't know what's causing this, but I suspect it was something maybe redefined by the update. How do I remove this kotlin error?
PS: I really don't use kotlin at all in my project so idk why it's showing this error.
Thanks in advance, AFSC.

Did you import a kotlin library instead of a java one by mistake? Recognizable by the ktx suffix.

Related

How to make ProgressiveMediaSource usable in ExoPlayer? Symbol not found

I am working on a project where I am trying to implement ExoPlayer to replace a VideoView. My issue is that I am getting this error: cannot find symbol class ProgressiveMediaSource
I have seen Why can't I locate ProgressiveMediaSource? and note that it is mentioned that ProgressiveMediaPlayer was added in ExoPlayer 2.10.0 - I am using 2.10.1 so version shouldn't be an issue. The other condition that was mentioned was having the Android project upgraded to AndroidX. I believe that I am only using AndroidX unless one of my dependencies is importing some support libraries (com.android.support).
The compiler throws an error on import:
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
If providing my gradle build script would help, let me know.
Error was due to human transcription error. I had typed progessive instead of progressive and never noticed until much later 😫
Lesson: if a symbol can't be found, make sure you spelled it correctly.

Possible reason for "Error:cannot generate view binders java.lang.NullPointerException"

I am using Android Studio for my Android projects. I faced an issue when builds crash with strange stacktrace, like this:
Error:Execution failed for task ':app:compileDevDebugJavaWithJavac'.
java.lang.RuntimeException: failure, see logs for details.
cannot generate view binders java.lang.NullPointerException
at android.databinding.tool.reflection.ModelMethod.isBoxingConversion(ModelMethod.java:155)
at android.databinding.tool.store.SetterStore.isBetterParameter(SetterStore.java:946)
at android.databinding.tool.store.SetterStore.getBestSetter(SetterStore.java:838)
and it was seemed that the databinding became broken as whole.
I made refactoring before and moved classes between packages.
In my case, I relied on Android Studio when renaming and moving classes between packages. But it didn't proceed correction for XMLs of layouts where were references on refactored classes in the type attribute of variable element in data.
So my previous type's value pointed to non existing files and build crashed.
It's simple mistake but it may take more time to find the source. Hope this would help someone.
For me, this started happening after updating Android Studio to version 3.5.2
To fix it, I downgraded Android Gradle Plugin
buildscript {
repositories {
//..........
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
//......
}
}
Make sure you import all classes you reference in xml bindings
I had code something like:
android:visible="#{obj instanceof A}"
I was getting that same error.
Turns out that class A was not imported on top. Adding <import type="com.company.A"> tag resolved the problem.
P.S. android:visible is a custom binding adapter I have.
If this question is still relevant. For me I figured that in my xml layout file I was including a class (not an instance of one) as a variable, i.e I had this code
<variable
name="Converters"
type="com.example.flexapp.utils.Converters" />
and it should have been
<import type="com.example.flexapp.utils.Converters"/>
since this was a class and not an object.
in my case my problem was in a LongClickListener that the method for this listener must have returned a boolean but my method returned void so when I added the correct return statement it worked just fine.
keep in mind if you use a data binding method you must return the correct value or else the error it throws is not helpful at all.
You may have stumbled upon this question after migrating to Android X. If that's the case, and you're positive your XML files are okay, but it's still not working, you should start looking at libraries that generate code.
Libraries that generate code cannot be easily converted by the Jettifyer. Some info here - https://blog.danlew.net/2018/11/14/the-reality-of-migrating-to-androidx/
In my case, I updated the obvious ones, but I still was missing something. So, what I did was go into my develop branch (that wasn't Android X), ran a build, and dug into the build folder to see all of the libraries that generated code. Once I did that, I was able to look at the suspects one by one until I found the dependency that was causing this issue. You could either update it, or, in my case, remove it, and this error was resolved. :)
The getter function for any instance that you refer from your xml file might not have been defined or the getter function might not have public access specifier.
Downgrading Android Gradle Plugin to 3.5.1 fixed the issue for me
I face this problem when I define variable like this (Android Studio don't warning anything)
<data>
<variable
name="onGlobalLayoutA"
type="ViewTreeObserver.OnGlobalLayoutListener"/>
<import type="android.view.ViewTreeObserver"/>
</data>
And I solve it by
<data>
<variable
name="onGlobalLayoutA"
type="android.view.ViewTreeObserver.OnGlobalLayoutListener"/>
</data>
Hope this would help someone.
In my case, the reason was that I used a type for a variable which is another module and that module is added as 'implementation ' in build script. Changing to 'api ' resolved the issue.
Clearly not the same issue as the one posted by atlascoder but I mention regardless, maybe someone gits this article with the same problem as I had.
As #hiddeneyes02 mentioned, this started happen when upgrading from Android Gradle Plugin from 3.5.1 to 3.5.2, this seems to be the bug:
https://issuetracker.google.com/issues/143778134
When I built the project with the command tool I got the same errors as in this post:
When building Android project with Android Gradle Plugin v. 3.5.2 my builds fail
In my case I wrote wrong the name of my view model variable inside the XML file. I had it named VProgressBar instead of vProgressBar:
android:visibility="#{fatherViewModel.vProgressBar}"

Android Studio not recognizing Class "ILineDataSet" from MPAndroid Chart library

I am trying to create a line graph. I found a tutorial from the following site which I have been following:
https://github.com/PhilJay/MPAndroidChart/wiki/Setting-Data
The problem I am having is with this line of code:
List<ILineDataSet> dataSets = new ArrayList<>();
Android studio does not seem to recognize the type "ILineDataSet" and as a result is preventing me from proceeding any further in completing this task.
It has offered solutions to resolve it, which are:
Create Class
Create Enum
Create Inner Class
Create Interface
All of which I do not think will solve the issue as I assume the library has already configured this but for some reason its not being picked up by android studio.
Could someone direct me as to how I can resolve this issue?
Thanks!
I'm so stupid.
Library wasnt updated.
Please ignore this
I was going to ask if you added:
dependencies {
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
}
To your gradle.build

net.java.util.tagValue : Not resolvable

In my program, I am trying to import below classes but there comes a compile time error for this. Am I missing any jar there ? If yes, then which jar I am missing. Please help me.
"import net.java.util.TagValue;"
I am writing this in eclipse
A simple search on the net shows that net.java.util.TagValue class belongs to fixparser library. Make sure that this library is in your classpath when working on your project.

Android Facebook sdk Session.OpenRequest(myFragment) is undefined?

For some reason I cannot see the line of code:
session = new Session.OpenRequest(this).setCallBack(statusCallBack)
It gives me an error that Session.OpenRequest(myFragment) is undefined. Does anyone know why this is and how I can fix it?
Found out what i was doing wrong. It has to be a fragment from the support library. I was extending the regular fragment class.
Apparently, Session.OpenRequest(Fragment fragment) constructor should work. Assuming that you have added Facebook SDK properly in your project, organize the imports in your class to import the Session.OpenRequest class. This constructor seems to be invisible for your code.
If you are using Eclipse IDE organize imports by pressing Ctrl+Shift+O.

Categories

Resources