Setting up LWJGL with Eclipse Mac Error - java

I have been following this link in order to set up the workspace, named "towerpg" (I wanted to create an RPG game in Java): https://www.youtube.com/watch?v=0v56I5UWrYY&feature=iv&src_vid=VS8wlS9hF8E&annotation_id=annotation_3428321851
I've followed every single step on the YouTube Video, however, I'm getting this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:96)
at org.lwjgl.Sys.<clinit>(Sys.java:117)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at towerpg.Main.main(Main.java:11)
My code:
package towerpg;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
public class Main {
public static void main(String[] args) {
try {
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
}
}
Not sure what I did wrong here, I've done everything I'm supposed to do. Is someone able to help me?

Add a JVM option that says:
-Djava.library.path="/path/to/mac/native/files/directory"
The directory should be in the downloaded LWJGL files.

Related

How to use pre-trained .model file for predictions in Android Studio?

I have trained a Decision Table ML model in Weka 3.8 Dekstop Version. I have saved the model accordingly in my assets folder and configured the wekaSTRIPPED.jar file as well. At this point, the build seems to be working fine on Android Studio. However, when I try to use the classification model in Java, I am getting some red highlights - errors - over my code which I am unable to autofix.
I have visited some online guides here and visited this commonly used weka-android reference here and here. They follow the same structure as what I have been doing in my code (with different models), but mine does not compile in Android Studio.
package com.example.owner.introductoryapplication;
import android.support.v7.app.AppCompatActivity;
import weka.classifiers.Classifier;
import weka.classifiers.rules.DecisionTable;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;
import java.util.ArrayList;
public class Test extends AppCompatActivity {
public static void main(String[] args) throws Exception {
Test test = new Test();
test.start();
}
public void start() throws Exception {
//LOADS THE MODEL...
String rootPath = "/assets/";
String fileName = "PGBD_DecisionTableUPD.model";
//Classifier cls = null;
Classifier cls = (Classifier) weka.core.SerializationHelper.read(rootPath + fileName);
I expect the output to simply build; I don't expect any prediction output because I haven't specified the testing data-set. However, when I do click compile, none of the terms are highlighted red on the screen.
Specifically, immediately after I run it, I get Compilation failed; see the compiler error output for details. in the build console followed by:
"C:\Program Files\Android\Android Studio\jre\bin\java.exe" -Didea.launcher.port=64163 "-Didea.launcher.bin.path=C:\Program Files\Android\Android Studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\Owner\AppData\Local\Android\Sdk\platforms\android-28\android.jar;C:\Users\Owner\AppData\Local\Android\Sdk\platforms\android-28\data\res;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\build\intermediates\javac\debug\compileDebugJavaWithJavac\classes;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\build\generated\res\rs\debug;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\build\generated\res\resValues\debug;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\customview-28.0.0.aar\14e09720fc7f657365dec6e786490d47\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\localbroadcastmanager-28.0.0.aar\d791f241c61f09475b5d43561b131f77\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-vector-drawable-28.0.0.aar\c8f91860fd6811b7040ad585c1bb749f\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\interpolator-28.0.0.aar\73289dbc6711e8292415efe83a859a43\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-core-utils-28.0.0.aar\2dc7d30dd7abd1c4b0846462e1137cc4\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-core-ui-28.0.0.aar\b5199754cf7a7bf403b3073b69edcfe3\jars\classes.jar;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\libs\wekaSTRIPPED.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\slidingpanelayout-28.0.0.aar\32aa91f4149120a8a428b24c5291b432\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\viewmodel-1.1.1.aar\3477f32913f9b9934a8185f031c05533\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\drawerlayout-28.0.0.aar\bfb4eb97f205f1db9a43db5a200619a5\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\coordinatorlayout-28.0.0.aar\aba273524bbeff5bfab162bc52fb07b9\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\coordinatorlayout-28.0.0.aar\aba273524bbeff5bfab162bc52fb07b9\res;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\com.android.support\collections\28.0.0\c1bcdade4d3cc2836130424a3f3e4182c666a745\collections-28.0.0.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\documentfile-28.0.0.aar\e49f57095504cc48cc7ba2b26757daf1\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.3.aar\96728e03169a340c5e642682fbd18ff8\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.3.aar\96728e03169a340c5e642682fbd18ff8\res;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\swiperefreshlayout-28.0.0.aar\a560a21fcde6d062081d9c09634c92a8\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\cursoradapter-28.0.0.aar\733ca7f2a61e46bdb2164e238fe8c4b6\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\asynclayoutinflater-28.0.0.aar\f950d05bc8679714fb0d7642259e29eb\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\livedata-1.1.1.aar\400a5420ad5e4bcef8ebbebf2123e101\jars\classes.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\android.arch.core\common\1.1.1\e55b70d1f5620db124b3e85a7f4bdc7bd48d9f95\common-1.1.1.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\versionedparcelable-28.0.0.aar\12c3dd068050bf0422d8455749982d52\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\runtime-1.1.1.aar\68e9f88e3e623f899ee79dd4aa8966f1\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\print-28.0.0.aar\f12fdac753fb8cbf34b55eced23a29c7\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\loader-28.0.0.aar\0f1fa1caaba4127fdcb1d7bb76f1c144\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\viewpager-28.0.0.aar\bdf7976216feddc6d17d8052bf1807db\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-fragment-28.0.0.aar\df9931f8c3d84779819dccebe1aa6282\jars\classes.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\com.android.support\support-annotations\28.0.0\ed73f5337a002d1fd24339d5fb08c2c9d9ca60d8\support-annotations-28.0.0.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\android.arch.lifecycle\common\1.1.1\207a6efae6a3555e326de41f76bdadd9a239cbce\common-1.1.1.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\livedata-core-1.1.1.aar\f5b8b9e2bbbf6e16caa00d091d538f2f\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0.aar\0fefdb1435b453663f8b867197d75a41\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0.aar\0fefdb1435b453663f8b867197d75a41\res;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-28.0.0.aar\7eca742b05d3ca93c5f22855deb68690\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\b5690672012030cd411a187af3fc56e5\res;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\b5690672012030cd411a187af3fc56e5\jars\classes.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\com.android.support.constraint\constraint-layout-solver\1.1.3\bde0667d7414c16ed62d3cfe993cff7f9d732373\constraint-layout-solver-1.1.3.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\runtime-1.1.1.aar\b33f18eb28c72c82424fc1a72a917596\jars\classes.jar;C:\Program Files\Android\Android Studio\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMainV2 com.example.owner.introductoryapplication.Test
Exception in thread "main" java.lang.RuntimeException: Stub!
at android.content.Context.<init>(Context.java:67)
at android.content.ContextWrapper.<init>(ContextWrapper.java:30)
at android.view.ContextThemeWrapper.<init>(ContextThemeWrapper.java:40)
at android.app.Activity.<init>(Activity.java:643)
at android.support.v4.app.SupportActivity.<init>(ComponentActivity.java:46)
at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java:68)
at android.support.v7.app.AppCompatActivity.<init>(AppCompatActivity.java:62)
at com.example.owner.introductoryapplication.Test.<init>(Test.java:13)
at com.example.owner.introductoryapplication.Test.main(Test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Process finished with exit code 1
Though, from what I understand, I have already included the .model file in my assets folder; it should recognize the file path.
So this begs the questions: How would I enable Android Studio to process my PGBD_DecisionTable.model file and how would I use it with testing data (directly on the phone)?
Use .open("PGBD_DecisionTable.model") instead of .open(PGBD_DecisionTable.model).
You are trying to load a file from a constant String expression, not a static property of a class named PGBD_DecisionTable.

Open in default browser exception

I'm using Eclipse to develop Java Desktop applications. The Desktop class has a useful method called browse() which opens an URI in the system's default browser. My problem is that this feature isn't working anymore in Eclipse but still works fine outside of Eclipse e.g. when launching an executable Jar file containing the code.
Here's a short compilable example:
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class OpenExample
{
public static void main(String[] arguments) throws URISyntaxException, IOException
{
Desktop.getDesktop().browse(new URI("https://www.google.com/"));
}
}
I'm receiving the following exception:
Exception in thread "main" java.io.IOException: Failed to open https://www.google.com/. Error message: A device attached to the system is not functioning.
at sun.awt.windows.WDesktopPeer.ShellExecute(Unknown Source)
at sun.awt.windows.WDesktopPeer.browse(Unknown Source)
at java.awt.Desktop.browse(Unknown Source)
at OpenExample.main(OpenExample.java:10)
What could be the problem? Obviously the Java code is right and since it worked before, something must be broken in Eclipse or maybe even Windows.
It might be related this this JDK bug: https://bugs.openjdk.java.net/browse/JDK-8064934
I.e. there might be a real error occurring, but the JDK is reporting the wrong error code because of this bugs.
import java.awt.Desktop;
import java.net.URI;
public class OpenExample {
public static void main(String[] args) throws Exception {
String url = "http://google.com";
if (Desktop.isDesktopSupported()) { // for windows
Desktop.getDesktop().browse(new URI(url));
} else { // for linux
Runtime runtime = Runtime.getRuntime();
runtime.exec("/usr/bin/firefox -new-window " + url);
}
}
}
try this Some times it depend upon OS as well .
Check print Statement giving URL or not .
if it will work please give your review

Getting 'Exception in thread "main" java.lang.NoClassDefFoundError: org/ini4j/Ini' error after succesfully compiling source file from the CLI

Background:
I am trying to use ini4j for the purpose of parsing config files in the ini format.
I run the command:
javac -classpath ini4j-0.5.4.jar Driver.java
and the compilation goes smoothly...however when I attempt to run the program running:
java Driver
I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/ini4j/Ini
at Clock.main(Clock.java:13)
Caused by: java.lang.ClassNotFoundException: org.ini4j.Ini
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
From what I understand this error is a product of the jvm being able to find the class file being referenced in the error and failing. I checked the ini4j jar file and confirmed that the Ini.class file does in fact exist. Can anyone please tell me what am I missing here ?
The following is my source code:
import java.util.Map;
import java.io.IOException;
import java.io.File;
import org.ini4j.* ;
public class Driver{
public static void main(String[] args){
System.out.println("running in Clock-J main()");
String fileName = "./test.ini" ;
File fileObject = new File(fileName);
try{
Ini ini = new Ini(fileObject);
}catch(IOException e){
String exception = e.toString() ;
e.printStackTrace();
}
}
}
You also need to specify the -classpath option when you run the program. Java will not automatically pick up the jar files that you passed when you compiled your code.
The correct answer for my situation appears to be:
java -cp .:ini4j-0.5.4.jar Driver
Thanks for pointing me in the correct direction guys!!!! Using an IDE causes one to forget stuff like this. I really appreciate it!!!! Thanks!!!!!
Look at Elipse->Properties->JavaBuildPath->Libraries
list of extended JARs have to be in CLASSPATH
please check for more info

JavaCV example is not working - what am I missing?

It's the first day of learning JavaCV for me. And this is the first test example which I use just to make sure that my setup is done correctly. Unfortunately I can't run the example and I barely understand the code and all dependencies so it's really hard for me to find out what is missing. Below I'll post my project setup and also the errors I get.
Also the example I use is from: http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/javacv-capture-save-flip-show-live.html
code
import static com.googlecode.javacv.cpp.opencv_core.cvFlip;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FrameGrabber;
import com.googlecode.javacv.VideoInputFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class GrabberShow implements Runnable
{
//final int INTERVAL=1000;///you may use interval IplImage image;
CanvasFrame canvas = new CanvasFrame("Web Cam");
public GrabberShow()
{
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
#Override
public void run()
{
FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
int i = 0;
try
{
grabber.start();
IplImage img;
while (true)
{
img = grabber.grab();
if (img != null)
{
cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise
cvSaveImage((i++) + "-aa.jpg", img); // show image on window
canvas.showImage(img);
}
//Thread.sleep(INTERVAL);
}
}
catch (Exception e)
{
}
}
}
I use Eclipse and it seems like all imports are there.
Here is a print screen of my project as it looks like in Eclipse:
So this is it for the setup. I try to get something out of this. When I right click on the project and try to Run it as Java Application the following windows is showing up:
You can see my choice at the top of the window. The I get an error window A Java Exception has occurred and here is part of the error I get in the console window:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Xman\AppData\Local\Temp\javacpp4929678155627\jniopencv_core.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:422)
at com.googlecode.javacpp.Loader.load(Loader.java:372)`
I've read the error, it seems like the problem is caused by missing libraries but I'm not sure, also I have followed the instructions (which weren't that many in fact) and from the comments below the example code it seems that it actually works. So I guess the problem is somewhere here - in my project, code, setup, but I can't find what I'm missing or doing wrong.
This error occurs when your opencv dll are not set in System path.
If you have extracted your opencv folder in C:\ directory then set your path as following
For 32 bit:
C:\opencv\build\x86\vc10\bin;C:\opencv\build\common\tbb\ia32\vc10\
For 64 bit:
C:\opencv\build\x64\vc10\bin;C:\opencv\build\common\tbb\intel64\vc10\
If you have extracted in different location then change the path accordingly.
In order to set path you can go to Control Panel > System Security > System > Advanced System Settings > Environment Variables. In System variable select path and click on Edit and insert above locations and restart windows.
you can find detailed instructions at http://opencvlover.blogspot.in/2012/04/javacv-setup-with-eclipse-on-windows-7.html
Download and install : Microsoft Visual C++ redistributable package (32-bit): vcredist_x86.exe

OpenGL in Java on Netbeans: NoClassDefFoundError

I am on a Mac running Netbeans 6.9.
I downloaded and installed LWJGL using this tutorial down to the letter:
http://lwjgl.org/wiki/index.php?title=Setting_Up_LWJGL_with_NetBeans
I finished the installation and copied sample code to see if my system is working. I got a bug, and was not sure if it was because of faulty code or I was doing something wrong. So I shortened down the code to this little simple bit:
package javaopengl;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
//Testing
public class Main {
public static void main(String[] args) {
boolean fullscreen = (args.length == 1 && args[0].equals("-fullscreen"));
try {
Display.create();
Display.destroy();
} catch (Exception e) {
e.printStackTrace(System.err);
}
System.exit(0);
}
}
But I still get the same error:
run:
Exception in thread "main" java.lang.NoClassDefFoundError: =
Caused by: java.lang.ClassNotFoundException: =
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I am not sure what exactly is going on, Would you please tell me what is going on and how to fix it?
Note: When i am looking at the text in the development environment, it does not show those red lines indicating there are any errors.
What are you typing (or what is netbeans running) to run this? Since the Mac filesystem is fairly case-agnostic unless you've specified otherwise, running java javaopengl.main will look for a file main.java, which is there (Main.java will be returned). But the class is Main, and you can get this exception from the difference. If this is being run from an ant script, I suggest making sure you have the correct capitalization (the class should be javaopengl.Main). A simple way to test this is to delete everything except the class definition and an empty public static void main(String[] args) {}
Alternatively, you could have something simpler, like your classpath out of whack. Missing the lwjgl jar would get you there, but if you followed the directions in that tutorial, that actually seems less likely. Still, you can test this.
package javaopengl;
public class Main {
public static void main(String[] args) {
System.out.println("well, main works");
Class checkjar = Class.forName("org.lwjgl.opengl.Display");
System.out.println("My ClassLoader found: " + checkjar.getCanonicalName());
}
}
Also, remove import org.lwjgl.Sys; from your shortened example. It doesn't appear to be needed, provided it isn't the source of your problems :).

Categories

Resources