Can't import MediaPlayer from External Libraries - java

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.

Related

Updating JAR Library in NetBeans

I have a JavaFX project that I have been programming in NetBeans. I'm using a version of a JAR file in my libraries and a newer version has come out. I tried to remove the first version and then add the new version in by right clicking the Libraries and then clicking "add JAR/Folder." It adds just fine but then all my imports will not resolve to the new version. I get errors saying that the import can not be found and none of my methods that use that library can find their objects either. If I right click on the little yellow lightbulb on the left, normally I would get an "Add import for ________" But that doesn't even show up. Only "Create class ______ in _______." I know the actual objects haven't changed names and the imports are pointing to the right locations, none of those have changed either. If I add the old library back in it works fine.
Is there a way to update the library. Something like "Refactor to new JAR?"
After looking into it some more and doing some extensive trouble shooting. I figured out that the update was a bad file. By using a slightly earlier version of the jar file but still newer then the one I was using I got it to work. Guess I just need to wait for the developer of the "Update" to fix their file. Thanks guys

tink library com.google.protobuf.GeneratedMessageV3$ cannot be resolved

I recently tried to add the google tink library to eclipse and it always has a "com.google.protobuf.GeneratedMessageV3$ cannot be resolved" error, I normally never have any problems with adding libraries to my project, and from what I can tell it has something to do with the all key template files since the error only occours when I try to generate a new KeysetHandle with any key template, and the error only starts when i enter in the key template file# https://github.com/Gameidite/testProject
The Protobuf library can generate Java classes for you. You need to find where these .class files have been output to (eg there should be a GeneratedMessageV3$.class somewhere) and make sure that they are included on your classpath. There's presumably somewhere in Eclipse where you can configure where it looks for class files - you'll need to add the generated files there.
If the generated class files don't exist yet you need to figure out what to do to generate them. It might be easier to use Maven or Gradle as suggested in the Tink documentation rather than directly adding things to Eclipse.
I think it's probably because Eclipse cannot find the protobuf Java runtime. Have you tried adding Tink to your project with Maven or Gradle?

add extra resources to the library

I am new to Java, so, my question may be so simple for you. But I am trying to solve this issue for ages.
I am not writing my code. It is from MATSim. Their codes have two versions: one from 2009, and the other from 2013.
please see this screenshot:
If tis picture does not work please see it via tweeter: ScreenShot
I have downloaded the 2013 version and added its library according to the guidelines. BUT the code up in Eclipse is a code from 2009 and as you can see some of the classes needed for this code is removed from the 2013 library.
***>>>>>>For example, this one is not in the library:..... import org.matsim.core.scoring.PlanScorer;<<<<<<<<<<<***
import org.matsim.knowledges.Knowledges;
import org.matsim.locationchoice.constrained.LocationMutatorwChoiceSet;
import org.matsim.locationchoice.constrained.ManageSubchains;
import org.matsim.locationchoice.constrained.SubChain;
import org.matsim.planomat.Planomat;
import org.matsim.planomat.costestimators.DepartureDelayAverageCalculator;
import org.matsim.planomat.costestimators.LegTravelTimeEstimatorFactory;
import org.matsim.population.algorithms.PlanAlgorithm;
**>>>>>>> or these specific classes: ..... import playground.mfeil.MDSAM.ActivityTypeFinder;
import playground.mfeil.config.PlanomatXConfigGroup;<<<<<<<<<<**
Fortunately I found their .java files from their archive. I tried to put them in the .jar folder and add them to the library via >>> properties/Java Build Path. But this didn't work for me.
I wonder if you help me in this matter. Please if you know how to do it, help me in how to change the path of files in the above code too. Is it enough just to change the path manually?
Your help is much appreciated.
Thank you,
Somayeh
Guessing around from the information you gave...
Option A:
According to MATSim's issue tracker, planomat does not exist anymore. The preferred way of replanning is adding smaller strategies to the MATSim config that change only one dimension at a time (instead of the best-response planomat). Check out the latest MATSim user guide chapter 7 for the strategies available and how to use them. The user guide is shipped with the latest release.
Option B:
If you really need planomat, fetch an older MATSim build. Planomat should then be part of the MATSim core. So there is no need of adding the playground of mfeil to your build path. Again, I do not recommend this. The preferred way is option A.
There is not really sufficient information here, so I'm going to guess a little bit about what you are doing and what the problem is. It is really helpful if you say "I got this error message at compile time (or runtime) and here it is, and then paste that into the post. Otherwise we're left guessing.
I think you have two versions of a library that you are trying to use from code that you did not write, and that the code uses one of the versions but you have the library for the other one. (Again, this is stuff you could put into questions to make them more complete "I have version 2009, there is another version from 2013...").
You should not need source code for the modules you do not have; in particular, it would be a bad idea to use source code just for those that aren't found in one version and the other version's library -- they are bound to be incompatible.
Java libraries are generally distributed as 'jar' files (extension of jar); I think your problem might be solved if you have a jar file for the library version being used and put it on a "classpath" so your compiler and runtime can find it.
We'll be happy to help you set a path to use a different version of the library, but you have to tell us how you're compiling. There are several popular IDEs (eclipse, IntelliJ, others) and the ol' command-line special. The setting of paths for these are all different.

Implementing ActionBar-PulltoRefresh by Chris Banes, library errors etc

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.

Cannot find the "GoogleAccountManager" in the google plus example

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.

Categories