Cant' load .ogg music files into Eclipse project in Slick2D - slick2d

Hi I'm very new here and I,m learning how to use Slick2D game library. I'm using Eclipse Luna IDE for coding. Everything was working fine till now but when I tried to load a music with ".ogg" extension, the problem occured.
I try to load a music by this line of code
music = new Music( "res/game_music.ogg" );
An exception occurs like this,
AL lib: FreeContext: (000000000E2F08A0) Deleting 64 Source(s)
Exception in thread "main" java.lang.NoClassDefFoundError: com/jcraft/jorbis/Info
at org.newdawn.slick.openal.OggInputStream.<init>(OggInputStream.java:35)
at org.newdawn.slick.openal.OggDecoder.getData(OggDecoder.java:311)
at org.newdawn.slick.openal.SoundStore.getOgg(SoundStore.java:835)
at org.newdawn.slick.openal.SoundStore.getOgg(SoundStore.java:793)
at org.newdawn.slick.Music.<init>(Music.java:135)
at org.newdawn.slick.Music.<init>(Music.java:74)
at main.Game.init(Game.java:48)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
at main.Game.main(Game.java:33)
Caused by: java.lang.ClassNotFoundException: com.jcraft.jorbis.Info
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more
I can assure you that
1. I've looked on the internet for enough time to find a solution and surprisingly I could not find anything helpful even though many other people have faced similar problems.
2. the "res/game_music.ogg" is in the right place. I am new here and can't include pictures in my question otherwise I would include a screenshot to show that the file is in right place.
Important note:
I faced some confusions when setting up the project. I don't want to lengthen my question now so I'm not talking about that now. But if anyone here tells me that my problem here is related to lwjgl.jar/slick.jar/native files etc. then I will include it.
At this moment just know that before trying to load music, every other render/update thing worked fine.
Would appreciate any helpful answer.

You have to include 2 jars in your project.
Download the Slick2D archive, and then add lib/jogg-0.0.7.jar and lib/jorbis-0.0.15.jar to your project.
Hope it helps.

Related

How do I add external libraries to Processing?

I am unable to add external libraries to processing.
I've followed multiple tutorials and looked at other Stackoverflow questions but none of them do the job.
I've unzipped the library and put it into the libraries folder inside of Processing, but it still hasn't worked, I have tried with 2 different libraries, the main focus being P5irebase.
https://github.com/barneyElDinosaurio/P5ireBase
I expect the examples to show up, and to also have the option to import the library, but none of that ever shows up. No contributed libraries in the import library section under the Sketches button, and no examples for contributed libraries under libraries which is under the File button.
Processing Forum Link: https://discourse.processing.org/t/how-do-i-add-external-libraries-to-processing/12750
All help is appreciated! Thanks :)
EDIT: After changing P5ireBase-master to just P5ireBase I get the error
java.io.FileNotFoundException: C:\Users\reedm\Documents\Processing\libraries\P5ireBase (Access is denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at processing.app.Util.copyFile(Util.java:130)
at processing.app.Sketch.addFile(Sketch.java:1355)
at processing.app.ui.Editor$FileDropHandler.importData(Editor.java:480)
at javax.swing.TransferHandler$DropHandler.drop(TransferHandler.java:1544)
at java.awt.dnd.DropTarget.drop(DropTarget.java:455)
at javax.swing.TransferHandler$SwingDropTarget.drop(TransferHandler.java:1282)
at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(SunDropTargetContextPeer.java:538)
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(SunDropTargetContextPeer.java:852)
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(SunDropTargetContextPeer.java:776)
at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:48)
at java.awt.Component.dispatchEventImpl(Component.java:4744)
at java.awt.Container.dispatchEventImpl(Container.java:2297)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:4609)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4471)
at java.awt.Container.dispatchEventImpl(Container.java:2283)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
I saw in your Processing forum link that you tried to drag&drop the library into Processing IDE and you've got this error :
java.io.FileNotFoundException:
C:\Users\main\Documents\Processing\libraries\P5ireBase-master
You see the "-master" at the end of your Library folder ? Well, it comes from GitHub and indicates the code branch you downloaded. Juts remove it from the folder name and your library should work as expected.
With Processing, you're library folder must always have the same name of the main .jar file in the "library" folder. So in your case, P5ireBase.
I hope that's the only issue and that everything works fine now for you.

Error to connect database in Eclipse JDBC ODBC,

I'm looking for resolve problem with eclipse, im trying to connect to MySQL via ODBC im using java 1.7, and the same code in NetBeans, and Eclipse,
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Gtable","root","");
In NetBeans it works fine but in Eclipse returns
Exception in thread "main" java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at testdb2.testd.main(testd.java:11)
How can i fix it ?
I added it to build path
it did not help
Im using this now,
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("sun.jdbc.odbc.JdbcOdbcDriver found");
} catch (ClassNotFoundException cnfe) {
System.out.println("Error: sun.jdbc.odbc.JdbcOdbcDriver not found");
}
And it returns jdbcodbc not found, where can i get that ?
The issue with the Eclipse project was that it was actually running under Java 8, so the JDBC-ODBC Bridge was not available. Changing the run configuration to use a Java 7 JRE solved the problem.
If you want to do this correctly, add a folder called lib to your current project.
Download the jar for the driver and drag this jar from your file explorer in your lib folder in eclipse.
After this, right click your project folder -> java build path, look for the libraries tab and click add jars.
Browse to your jar in the lib folder and click OK. After this click ok again.
This should work :)
Try this:
Class.forName("com.mysql.jdbc.Driver");
If this doesn't work, you probably gave the wrong path.
Try searching in your referenced libraries in the package explorer view.
Just expand the jar and look for driver.class.
If this is to much work, your could try searching with shift + ctrl + r.
adjust your filter to your needs.
You need to search for the path of driver.class
I also suggest you not to use root and give it a strong password
You should open project property (alt+Enter), open menu "Deploy Assembly", and set libraries folder, where you have jdbc driver.
Something like this:

Fetched from upstream eclipse github: java.lang.ClassNotFoundException

I'm trying to revert to a previous commit. I'm using Juno eclipse and github/egit.
Reverting works: I can see my old code. But when I try to run it, I get this:
java.lang.NoClassDefFoundError: mmPackage/Main
Caused by: java.lang.ClassNotFoundException: mmPackage.Main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"
My package is called mmPackage.
This exact code worked for me when I pushed it to github a few days ago. Now that I've revered to a previous commit, it just can't seem to find my class with a main method!
I have tried:
Building project
Making sure my src folder is in the build path
I also noticed my bin folder does not seem to contain any .class files. I tried deleting it using the file system browser and re-running, but no luck. And now I can't even see a bin folder in my file system!
Thank you!

How do I distribute a LWJGL jar?

I need help, I followed the following tutorial on setting up my project.
http://lwjgl.org/wiki/index.php?title=Setting_Up_LWJGL_with_NetBeans
And I added the following run command
-Djava.library.path='C:\Program Files (x86)\Java\lwjgl-2.8.3\native\windows'
And my project wors great in netbeans, however I can't distribute my application as I double click the jar I recieve a noClassDefFound exception.
My dist folder contains the following 2 files, no natives.
/dist/Engine.jar /dist/lib/lwjgl.jar
I am sure this is due to my natives not being included in my dist folder, I have tried searching the net and I have yet to find a solution that works, Please any help you can give me would be great, thanks.
I found a solution to my issue, I thought I would share it with others, as a lot of people seemed to have suffered like myself.
I was receiving the following exception on run,
Exception in thread "main" java.lang.NoClassDefFoundError: engine2D/engine/Engin
e
at Engine2D.Game.<init>(Game.java:42)
at Engine2D.Game.main(Game.java:48)
Caused by: java.lang.ClassNotFoundException: engine2D.engine.Engine
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
This was due to case-sensitivity which was ignored by netbeans, so whenever
engine2d.engine.Engine
was invoked it referenced the following.
Engine2D.engine.Engine
But when ran locally, I hope this helps others and I can get back to working on my game.
Thanks Gary

Jar cannot be opened on different Computer ("Can not find main class")

Today I programmed myself a Little game, which I compiled into a jar through Eclipse - I made sure its a executable jar, or runnable jar or however you want to call it.
I've sent the jar to a friend of mine, but oddly he's not able to open it.
He's always receiving the "Can not find main class" error, which shouldn't pop up since it works perfectly for me. I've already googled but was not able to find a answer.
If you're interested, you can take a look here, if it works for you:
http://www.file-upload.net/download-3939961/WidzDeluxe.jar.html
Now the question I have is kind of obvious I guess, is the error only for him or do you all have the same problem? What's the cause of it?
If people wish, I also upload the code.
You have compiled class files bundled inside this jar with a different (higher) version of Java. Presumably it was Java 1.7 and the friend of yours is trying to open it with Java 1.6.
Here is the stacktrace I received trying to open your executable jar with Java 1.6.0_21:
Exception in thread "main" java.lang.UnsupportedClassVersionError: NewJFrame : Unsupported major.min
or version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: NewJFrame. Program will exit.
One possible solution that came to my ming would be to set the compliance level to let's say 6.0 in Java Compiler settings in Eclipse. That should to the trick.
I had this same problem, found I was compiling the program for Java 1.7. I ended up updating Java on all my computers that I was running it on and it worked great.