Ok I read too many Threads from many people who somewhat have a similar problem but none of them solved my problem so please assist me with my huge "pain in the ass"-problem which I seem to not fully understand.
I'm trying to use the MediaPlayer Class from javafx.scene.media and sadly the media class isn't inherited in the default SDK's since Java 9 I think and I'm using Java Version 12. So naturally I have to add the jafafx.scene.media library (jar-Format) manually which should be the easiest step in the world.
I am able to add it via "Project Structure -> Libraries -> Add Library" and it shows up in my external library menu but none of my classes can import it.
That's my first Java project (I come from C#) and I even asked my proffessor but he didn't have a clue either. I even tried to create a new project and add it but with no success.
(I tried adding the library via Maven-Dependency, too, with no success)
Then I thought that another library could work and I added vlcj (VLC-Player) and at least it does find something to import after going to "Project Structure -> Modules -> Dependencies" and changing the vlcj library from compile to Provided.
But now when importing I get the following error:
Error
I am so confused. And it's even for a school project.
Please give me advice if you have any or tell me if I need to drop more infos.
Much Love
Kong
Adding a library is not enough, the library must be also in the module dependencies.
Also, if you are using Java 9+ module system, you have to adjust your module-info.java file for that. Or just delete this file and don't use Java modules for this project for the sake of simplicity.
I am new to kotlin, i have converted some code from java but it seems like there's something wrong, The R in findViewById(R.id.my_id) is highlighted in red and it shows this message : "Unresolved reference: R".. I've been looking for a solution but i seem not to figure it out, So what should i do?
Here's a screenshot :
The issue can be caused by many factors,
as mentioned by martomstom in this Answer the issue is sometimes caused by com.android.tools.build:gradle version, changing it's version to a more stable one would solve the problem: for example: com.android.tools.build:gradle:3.4.0-alpha02 with com.android.tools.build:gradle:3.2.1
Also, having libraries from the same group, but with different versions may cause the problem or even more runtime errors. use the exclude group method like the following : implementation('com.squareup.picasso:picasso:2.71828') { exclude(group: 'com.android.support') } in this case, picasso library uses android.support components, the android library version used in picasso is different than the one you're currently using in your app, so in order to solve this issue, we have to exclude it completely from its sub library and class groups.
It can also happen by the mismatch of resources and code, including this importation line in your activity may solve the problem too : import com.package.name.R
Sometimes it can happen because of the IDE, performances or memory.. Cleaning the project from time to time may save you some time, on Android Studio it would be something like this : Build -> Clean Project / Rebuild Project - Cleaning IDE cash also helps with performance and memory, on Android Studio it would look like this : File-> Invalidate Chases/ Restart -> Invalidate Cashes and Restart
I noticed that this problem happens to me the most of the time when importing new resources, Using prohibited characters in their names would fire the error, such as . , , - , UpperCase or special Letters
And as a suggestion , if you're using Kotlin, i really recommend using Kotlin extensions in your activity such as : import kotlinx.android.synthetic.main.activity_page.* or if you're using a custom view : kotlinx.android.synthetic.main.view_layout.view.*
after that, in onCreat() method of an activity , you'll only have to call the id, for example : my_edit_text_ID.text = "Kotlin Dbest!", or from a custom view : mCostumView.my_edit_text_ID.text = "Kotlin Dbest!"
EDIT :
I have faced this issue againe and the problem was the '' R '' library was imported from 2 different sources :
com.android.R
com.example.package.R
You must only import the '' R '' library with your application package name,
in this case com.example.package.R
Sometimes the library is not imported at all, to import it, click on the
unresolved reference R and press Alt + Enter
EDIT:
As tobltobs mentioned in the comments section: " Most of the time the problem is caused by another error which prevents the build system from creating generated sources. To find the root cause look at the gradle log (the "toggle view" icon below of the green hammer in the Build output) and look for errors unrelated to R or BuildConfig (also generated). If there is no other error left and the problem with R persists then maybe something of this list might help. "
EDIT:
As Patrick Beagan mentioned, Kotlin extensions are now deprecated - I'd advise using ViewBinding instead
I used com.android.tools.build:gradle:3.3.0-alpha13 and had the same issue. Changing to stable Version 3.2.1 solved this problem for me.
So this is a misleading error.
The fastest way to get to the root cause is to run:
bash gradlew assembleDebug --debug
then scroll up and look for the real error happening.
However, if it still doesn't seem like you have the answer you are looking for, then read on.
I'm going to explain the 30,000 foot view of what is happening. This is not EXACT order or EXACT flow, it is just pretty damn close ;) so if you know more then I do of the exact order and care to make corrections with links, feel free I won't stop ya :).
The Process
The R file is generated code.
There is an order to the generation.
Gradle will do it's magic, pull it's dependencies and kick off it's
warning and error tree first,
then Android converts all Kotlin to Java behind the scenes. Yup that's
right, our beloved Kotlin still has to be Java to compile for our
beloved ART virtual machine.
Then it runs through and does the adapters that you have created for
JVM Statics and a few other tasks.
Next up it compiles all the xml databinding files first to create the
generated databinding files.
If everything succeeds it moves on to processing the assets and
resources. Which creates pointers or IDs for each resource that you
reference in code. Next it will run through and begin compiling the
code and packaging process after that.
Pretty straight forward process, but here in lies the problem.
The misleading Error
If any step fails before the R generation is complete, then the R does not get generated. Sometimes a simple rebuild is all you need to do, sometimes a simple File->Invalidate Cache and Restart is all you need. However, more often than not you have a code issue in your gradle, your xml, your databinding or your adapters that are preventing the compiler from even reaching the R generation stage.
So the next question is
"Well shoot, how do we troubleshoot it if the errors are worthless or
non-existent".
Well first let's talk about the many ways these errors present themselves.
Duplicate Databinding class found
xml Binding Error at line #
Couldn't find matching signature of bind:customAdapterMethod
Can't find R file of the correct project, only shows import options for sub modules or incorrect namespace R files.
Couldn't find DataBindingUtility or DataBinding for activity/fragment
And many other various ways as well, too many to list them all
Next, let's talk about potential candidates causing the problem. As there are sooo many lol.
Gradle Syncing issues
Bad versions of Gradle or Tools, you may have gone too far forward in your last gradle file modification. Try stepping back one version and "invalidate cache and restart" if that fixed it, great, if not, read on.
Caching Issues (File->Restart and Invalidate Cache)
xml elements with wrong namespace
xml elements with bad IDs or references IDs out of order (i.e. you say align to right of an element that is lower in the xml document then the sibling element that is trying to reference it)
xml data binding issues referencing namespace or member that doesn't exist or is not typed correctly
xml data binding issues in non-auto-filled spots like custom attributes using adapters as those are harder to spot. i.e. bind:myCustomMethod=#"myObject.mistypedProperty()"
JVM Static adapters with issues or duplicated signatures
Duplicated or bad character in the Strings or Dimens file or any other xml file for that matter
Private variable marked for #Binding without properties to access it
Member variable marked for #Binding that matches a parent class method causing duplications that manifests itself in almost impossible errors
Mismatch of types like using an adapter that takes (Int) but you are passing (Int?) via data binding and it isn't recognized with JVM Statics until compile time
You selected IMPORT on a popup to import R file of a sub module instead of the application file
Having bindable members in a child or parent class, but not giving fully qualified namespace to class cast in the XML usage of the parent or child class. As the databinding compiler is not smart enough to realize the variable provided for class Foo is also parentFoo baseclass, so you have to qualify it as android:text="#((com.path.parentFoo)foo).parentMethod"
Having a method name in a class, that matches a "generated property from #Binding member variable" i.e. firstName as a variable, but then having a method called getFirstName in a parent or child class, because you are now matching a method name that will get auto generated, thus causing dataBindingUtility duplication class errors.
There are more causes, but this should give you a series of places to look, but the list can go on and on seriously.
Unfortunately this happens a lot in bleeding edge technologies where the UI tools are not up to speed with the terminal based tools yet. So I suggest you run from the project root in a terminal with
bash gradlew assembleDebug --debug
When it fails, and it will. Start scrolling up through the logs until you find the red where you see what is actually failing and preventing the next stage from occurring.
You will find this especially useful when you start dealing with databinding.
TIP:
When you start dealing with databinding, make sure you compile and run often because the goal is to recognize right away before doing other files to make sure you didn't break generation and make your life MUCH easier to know code you just added caused the issue before getting too far.
Times to compile and run to confirm no issues before moving on.
If you add a few JVM statics compile and run
If you add variables to your XML to use
If you bind to properties of your model in 1 file
If you add a binding to a JVMStatic
If you add bindable members or properties to an model
If you refactor moving observable member variables or properties into children or base classes
Any other xml or binding related elements that can effect the generated code.
Like I mentioned above, the reason is to avoid getting so many changes, that it becomes a troubleshooting nightmare to find a generic vague, horrible error related to generated databinding code. I'm sure the tools will improve, but for now, do yourself a favor and compile and run often when changing Databinding related items.
Happy Coding
Use gradle commands.
In Android Studio, on the right menu:
Gradle -> :app -> Tasks -> build -> clean.
After that, Gradle -> :app -> Tasks -> build -> build
I had wrong import statement import android.R instead of import my.project.package.R. Fixing it solved the problem
I had the same problem, and I tried not to downgrade from gradle version 3.3 to gradle version 3.2.1. Instead I updated Android Studio to version 3.3, which made the trick for me ;-)
This worked for me. How much work it is depends on how big your project is. I started a new project, created the required modules (XML, Kotlin, colors, strings, etc.), then copied the code into the modules in the new project from the modules in the old project. Copying XML saves a lot of time compared to recreating the UI. All in all, it take a little while, but I have spent much more time tring to fix the unresolved reference error without it.
TRY THIS
Go to the content_main.xml file and there you need to change the
android:id="#+id/??????"> line of code to whatever id you have given to your file.
Replace question mark ?????? with the related file id name.(IF you dont know the id go to the design tab on the bottom and click on the related Asset.
On the right side below attributes, you can find the ID you have given to it.
If it is blank you can freshly name it and Android Studio will write the code.
Then restart Android Studio. Hope this will help. Happy coding.
I believe that I came across the real answer (though by accident).
I also, as the OP had my KT file fail to location R. as well as other classes that happen to be in java. What I noticed was that there was a case difference I the filenames. Once I corrected the import statements to match the case of the package (aka, folder) the errors resolved.
I had the same problem with R reference too.
Finally Android Studio 3.3 has been released and using 'com.android.tools.build:gradle:3.3.0' the problem has been fixed!
I update Android Studio to version 3.3.1 and solved this problem.
Downgrading gradle version worked for me.
I changed :
Gradle version from : 4.10.4 to 4.4.1
and Gradle Plugin version from : 3.3.1 to 3.1.3
If your are experiencing this issue in Kotlin because you cannot reference the elements of the xml layout by ids. (e.g. R.id.adView) then try removing the line import android.R from your kotlin file.
For me it was because I had created a new package and R wasn't available until I imported it from the package above
I faced the same issue. I restarted my Android Studio, invalidate caches, Sync Gradle but nothing was working. Then I looked into my file and there are 2 imports of my R. 1 import was related to my application package and the other was related to Android.
import com.example.myApp.R
import android.R // This import was added accidentally during the build.
Removing second import related to android solved this issue.
I had an issue because of this import:
import android.os.Build.VERSION_CODES.*
In the latest version it contains R
I had same problem while using auto-manifest plugin. Adding AndroidManifest.xml explicitly solved the problem to me.
I used to File --> Invalidate Caches... and issue resolved.
Just restarting Android Studio solved it for me.
I also had this problem, Gradle Sync, and Invalidate Cache, and Restarting Android Studio Didn't help. Upgrading and Downgrading Gradle were also not helpful.
What worked for me is: Make Project (Ctrl + F9) and then try to run the project.
I solved this error by following Android Studio's lint tools to upgrade the version of a dependency in the project-level gradle file. In this case, I upgraded androidx.navigation:navigation-safe-args-gradle-plugin from 2.3.2 to 2.5.2 (latest version), then synced the project.
Here is the solution,
File->Project Structure->Project, select Android Gradle Plugin Version as 3.2.1 from the drop-down. then click apply.
Following up on my previous question about importing a certain library from github in my project, I decided I wanted to implement a different one, but I get lots of errors at this point.
Importing Android Listview refresh by pull, project-properties error
In line with Google currently using Chris Banes' ActionBar-PullToRefresh: https://github.com/chrisbanes/ActionBar-PullToRefresh,
I've decided I wanted to used that library as well for the Android app that I'm currently developing for my internship. When I try to import the existing code into the workspace from the unpacked zip-file though, I instantly get a ton of errors, in the library as well as in the example activities. For instance, in the library folder, in ActionBarPullToRefresh.java, it underlines Class within the first private hashmap and says references to the generic type Class should be parameterized.
The IDE (eclipse) also gives tons of errors to the other folders included, and when I add the library folder to the libraries of my main project, using the properties -> android tab, it carries over the errors to that project (quite logically).
Could anyone send me into a direction as to how I should successfully import and use this library?
I will write this here for future PullToRefresh users. I use IntelliJ IDEA instead of eclipse, so remember that the word Module and Project are equivalent. When you have to add a project to Eclipse, the action is add module in IDEA.
Example with ActionBarSherlock (ABS from now).
What you have:
You have a Module named: MyProject. This is your main Android module.
You want to add PullToRefresh to a few Fragments (for example) in your MyProject.
Step One: Download and Copy.
I personally like to have a clone or fork of the libraries I'm using to read the commits and change logs. Not only you learn by seeing other people's code, but also you get the "latest news" about the libraries you use. It's a win-win situation. Remember what Jeff Atwood said: "Read The Source, Luke". So in order to do this, Clone ActionBar-PullToRefresh from the right URL.
Now I don't like having the clone with my modules/projects so I usually clone projects somewhere else and later manually move what I need. It's tedious but that way I only get what I want. So what do you need then? The clone contains two important directories: Extras and Library. We're going to need stuff from these.
Copy the library directory to your project root: /path/to/your/project/pulltorefresh
Copy the corresponding (ABS or Compat) extra to your project root as well…
This is what you got so far:
/path/to/your/project/MyProject
/path/to/your/project/pulltorefresh
/path/to/your/project/pulltorefresh-abs (or compat)
Step Two Import these:
Import these modules (projects in eclipse) into the project/workspace. This should be simple if you know your IDE, but as a quick reference: File -> Import Module -> find the pulltorefresh folder from above (and the -abs or compat later) and follow the wizard. If you're using Eclipse, check this link to know how to do it.
Now you should have in your left panel (⌘1) the following structure
MyProject
pulltorefresh
pulltorefresh-abs
Step 3 Add the right references
Assuming MyProject has actiobnarsherlock.jar (because you need it) or the corresponding android support library for compat and that you have the corresponding android-support-v13 (or v4) as well…
pulltorefresh doesn't need any library reference.
pulltorefresh-abs needs a reference to: pulltorefresh, android-suppport-vX and actiobbarsherlock
MyProject needs a reference to: pulltorefresh-abs, android-suport-vX and actiobbarsherlock
Of course both android-support and actiobarsherlock could sit in MyProject and be exported (and taken from there) by the other libraries, but that's project management 101 ;)
Step 4 Integrate!
This is easier, just follow the Quick Start Guide.
REMEMBER: in older versions of the lib you had to have an attacher in an Activity, that is no longer necessary. Read the documentation, it's very simple (and much more flexible this way).
Wait, What If You Don't Use Either Sherlock or Compat??
I haven't done this yet, but my guess is:
Don't import -abs or -compat in extras. Just import pulltorefresh.
From your project, reference pulltorefresh.
Hold on… what about imports?!
Getting the right imports is important for any library, you have to pay attention and not blindly let your IDE do it for you (or at least always double check what you're importing). You'd be surprised to see how many "name collisions" are out there.
For Action Bar Sherlock based projects, the imports should be:
import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout;
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;
For a non sherlock pure project:
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;
Where did you get those?!?!?!?!
By looking at the samples, Luke.
For example, here's for the stock version.
The final step would be to profit… but I leave that up to you ;)
If you still have an issue, the guys are friendly provided you don't ask lazy questions. Feel free to follow the project and participate in the issues page at github.
Good Luck refreshing!
I don't use Gradle myself, but we all should, as it is a quantum leap for build technology in the Java (JVM) world (from Gradle introduction). This is how to reference projects libraries for PTR v 0.9.3:
Your project has to reference PullToRefresh aka PTR
PTR has to reference SmoothProgressBar aka SPB, which you can find here, on github
Both PTR and SPB should be Android libraries, so make sure that checkbox is checked (Properties -> Android -> IsLibrary)
The "tricky" part: Once you have cloned SPB on your local machine copy the contents of SmoothProgressBar\library\src\main\java into SmoothProgressBar\library\src\main\src (that is the structure ADT expects)
remember to add the support library to SPB if you target lower that 14
Assuming you know how to reference an android library project in eclipse (if not, google it), that is all about you need to do.
Good luck! :)
Non-senior developers/git users might find the following link useful (like I did) http://www.rahuljiresal.com/2014/04/actionbar-pull-to-refresh-on-android/
rahuljiresal has created a git project that contains both Chris Banes' Actionbar-PullToRefresh AND the referencing SmoothProgressBar all in one: https://github.com/rahuljiresal/ActionBar-PullToRefresh
The steps described above by Martin i.e.
1. Download/ Clone git project locally
2. Import PTR library into Eclipse
3. Reference PTR library from your project
4. Integrate
are still valid, but the whole process is incredibly easier and plug-and-play.
My problem is simple: I would like to use the error function Erfc(double) in Java with Eclipse but I do not want to implement it (because it is complicated).
So, I have found this:
http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/special/Erf.html
That does exactly what I want. The problem is that I can not use it. As it is not from "docs.oracle.com", I can not just import it. But unfortunately, I can not include the library and use it neither because what I download from :
http://commons.apache.org/proper/commons-math/download_math.cgi
is not a .jar
Does someone know how to "install - use" it?
I use Ubuntu 12.04 on a Intel® Core™ i7-3610QM CPU # 2.30GHz × 8 and my IDE is ecplipse.
Ok, this was a stupid question! So I have found the answer by myself.
I just needed to download the binary files and add it as a .jar. Then it works as a classical library.
To use it, I must
import org.apache.commons.math3.*;
While trying the google plus API example from the project site I'm completely stuck with one import:
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
This thing just doesn't seem to exist in the project.
The sample is a read-made Eclipse project I imported, and to be sure I checked if the massive amount of .jar's in the /lib directory are added to the build path. They are, I can see them listed in the Referenced Libraries part in my Eclipse project.
I can find mentions of com.google.api.client.googleapis.extensions.android2.auth but there just doesn't seem to be any GoogleAccountManager class around.
Several possibilities I have come up with, but can't find out which is it, let alone find a solution to them:
I have not set up my project correctly. I doubt it, but completely possible. This would mean that the example has a broken project set-up and/or I managed to not import all libraries?
The class or package or something like that is renamed // named differently. This would mean the example is broken out of the box, and that I still need to find the correct class (and change the import + calling code to that)
Something else :D
The following are the contents of the libs directory as you can also browse on the project page . Notice that it does containt google-http-client-extensions-android2-1.6.0-beta.jar
google-api-client-1.6.0-beta-sources.jar
google-api-client-1.6.0-beta.jar
google-api-client-extensions-1.6.0-beta-sources.jar
google-api-client-extensions-1.6.0-beta.jar
google-api-client-extensions-android2-1.6.0-beta-sources.jar
google-api-client-extensions-android2-1.6.0-beta.jar
google-api-services-plus-v1-1.3.0-beta-sources.jar
google-api-services-plus-v1-1.3.0-beta.jar
google-http-client-1.6.0-beta-sources.jar
google-http-client-1.6.0-beta.jar
google-http-client-extensions-1.6.0-beta-sources.jar
google-http-client-extensions-1.6.0-beta.jar
google-http-client-extensions-android2-1.6.0-beta-sources.jar
google-http-client-extensions-android2-1.6.0-beta.jar
google-http-client-extensions-android3-1.6.0-beta-sources.jar
google-http-client-extensions-android3-1.6.0-beta.jar
google-oauth-client-1.6.0-beta-sources.jar
google-oauth-client-1.6.0-beta.jar
gson-1.7.1.jar
guava-r09.jar
On the first page is a link to updated Google plus libraries google-plus-java-starter_v5.zip
Updated Link: google-plus-java-starter_v5.zip
It contains android/libs/google-api-client-extensions-android2-1.6.0-beta.jar, which contains GoogleAccountManager class.
As this is an extension it probably needs other jars too.
(summary of comments)
Manually adding /libs/google-api-client-extensions-android2-1.6.0-beta.jar to the build path and verifying that it is in the Referenced Libraries fixes the problem. It is unknown (to me (Nanne)) why this doesn't happen automagically when adding the libraries, but there you are.
Right-click on Project, select Properties->Java Build Path->Order and Export Tab->click on checkbox for “Android Private Libraries”. That worked for me.