Why won't the OpenSimplexNoise Processing library work? - java

I'm trying to use this library called OpenSimplexNoise, made by GitHub user TheCodingTrain. But I immediately discovered that I couldn't use it.
I did some digging to try to figure this out on my own, and I discovered that the JAR file and the main folder should have the same name (for example, the library file would be named OpenSimplexName and the JAR file would be OpenSimplexNoise.jar), and the folder the JAR file is in should be called "library." Once I fixed these issues, OpenSimplexNoise appeared in the "Import Library" menu in the "Contributed" section. But once I clicked it, a bunch of code appears:
import japplemenubar.*;
import processing.awt.*;
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.javafx.*;
import processing.opengl.*;
along with the error message:
More than one library is competing for this sketch.
The import japplemenubar points to multiple libraries:
core (C:\Program Files\Processing\processing.3.5.4\core)
OpenSimplexNoise (C:\Users**\Documents\Processing\libraries\OpenSimplexNoise).
Extra libraries need to be removed before this sketch can be used."
I tried removing japplemenubar, but the same issue appeared with processing.awt, so I tried removing that, but it just kept happening with each different import. I tried deleting it all and just typing "import processing.OpenSimplexNoise.*;", but it said "The import processing.OpenSimplesNoise cannot be resolved."
Does this mean that I'm just doing something wrong, or is this library no longer usable?

I recommend watching/following the videos linked in the README and understanding those:
https://youtu.be/pI2gvl9sdtE
https://youtu.be/U0TGZCEWn8g
The tutorials are how to put organize/compile a basic Processing library from scratch, not how to use library itself.
It would've been easier if a distribution zip would have been uploaded, but the point is learn how to generate it.
Downloading the library zip and unzipping in Processing won't work.
You need to:
(install eclipse if you haven't done so already as part of the video tutorial)
clone / download the project on your computer
Import the project into eclipse:
Drag and drop the build.xml file into the Ant panel: (in my view I've got multiple Processing libraries, you might have just OpenSimplexNoise)
Press the green Play Icon to run the build.
Initially I ran into this error:
BUILD FAILED
/Users/George/Documents/eclipse/OpenSimplexNoise-for-Processing/resources/build.xml:107: The following error occurred while executing this line:
/Users/George/Documents/eclipse/OpenSimplexNoise-for-Processing/resources/build.xml:141: /Users/George/Desktop/OpenSimplexNoise-for-Processing/lib does not exist.
Instead of trying to debug/fix the xml file I simply made the folder structure it wanted: a desktop folder named OpenSimplexNoise-for-Processing containing a lib folder.
Smooth sailing after this: BUILD SUCCESSFUL
Part of the ant build is copying the library to Documents/Processing/libraries so you can simply run the examples from there:
FWIW I've uploaded the compiled library here.
If simply wanted to use noise in Processing the built-in noise() function would do the trick.
If you want Simplex Noise without compiling Daniel Shiffman's example library you could try toxiclibs and it's toxi.math.noise package (also comes with an example sketch).

Related

Importing libraries in .java tabs in processing

I'm kind of new with Processing 3.*; I am (and willing to) using the Processing Development Environment (The official IDE).
Reading the official "guide", in particular this part, it is specified that you can use pure Java language inside Processing simply naming a .java tab instead of a .pde one.
This kind of solution is good for example to use enums (otherwise not usable in .pde tabs) and there are other reasons, but they are not important at the moment...
A problem with this kind of work is that the libraries of Processing are not included, so you have to import them manually.
What I noticed is that all the official Processing libraries can be imported simply by the import keyword, while for all the libraries installed by the Contribution Manager the story is different.
The error message is The package "packageName" does not exists. You might be missing a library. Libraries must be installed in a folder named 'libraries' inside the 'sketchbook' folder.
Long story short I can't import those libraries...
I tried to copy them in the standard java libraries location (%SystemRoot%\Java\lib\ext) and in some other paths, but nothing...
I read that using classpath would allow as to use it but I can't understand how to use Processing with javac.
I also tried something like "ProcessingFolder\processing-java.exe" --sketch="$(CURRENT_DIRECTORY)" --run that is the same script you can use to run Processing in Notepad++, adding the statement --classpath="$(CURRENT_DIRECTORY)" (Obviously in Notepad++) but it didn't work (processing-java.exe state I don't know anything about --classpath=.).
So here's the question: How can we import and use libraries in .java tabs using Processing Development Environment?
That doesn't sound right. You should be able to use library classes just fine by importing them in a .java tab.
Step 1: From the PDE, go to Sketch -> Import Library, then choose the library you want to include. Notice that if you haven't included a library before, it's actually two steps: first you have to install the library, then you have to include it.
Step 2: Once you've included a library in your sketch, you can use the classes from that library anywhere in your sketch. This includes .java tabs.
Here's an example that uses the minim library in a .java tab. I didn't have to copy any files or create any directories:
Main sketch tab:
void setup(){
Test test = new Test(this);
}
Test.java tab:
import processing.core.PApplet;
import ddf.minim.Minim;
import ddf.minim.AudioPlayer;
import ddf.minim.AudioInput;
public class Test {
Minim minim;
AudioPlayer player;
AudioInput input;
public Test(PApplet sketch) {
minim = new Minim(sketch);
player = minim.loadFile("song.mp3");
input = minim.getLineIn();
}
}
It sounds like you aren't properly including the library in your sketch. Make sure you go through the Sketch -> Import Library menu, and make sure you both install and include the sketch.

package org.pdfbox.cos does not exist

I am trying to import and use PDFBox, but am having issues installing the jars I believe.
I am using Dr. Java, and I have added both the pdfbox-1.8.6.jar and the pdfbox-app-1.8.6.jar to my resource locations in my Extra Classpath.
However, it still is not recognizing the jars when I run the code:
import org.pdfbox.cos.COSDocument;
import org.pdfbox.pdfparser.PDFParser;
What other steps do I need to do in order for the jars to work?
Use the correct imports:
import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.pdfparser.PDFParser;
Additional hints:
pdfbox-app-1.8.6.jar contains the classes from pdfbox-1.8.6.jar, so you don't need pdfbox-1.8.6.jar too
if you want to load a document for rendering or text extraction, you won't need these two imports. Loading is done with
import org.apache.pdfbox.pdmodel.PDDocument;
PDDocument doc = PDDocument.loadNonSeq(new File(filename), null);
To see how it is done, look at the examples in the source code. Good luck!
Have you tried the steps detailed on the documentation:
Adding And Removing JARs in DrJava
A JAR file is a way of storing many (pre-compiled) Java classes. Below
are instructions for adding and removing jar files from DrJava's
resource locations. For more information on JAR files, see our JARs
page and Using JAR Files: The Basics on Sun's site.
How to add a JAR
When you download the jar, keep track of where you save it to
Open DrJava
Edit > Preferences
Resource Locations (at left)
In Extra Classpath, Add (browse and chose the new jar)
Apply
Okay
Quit DrJava and re-open it in order for the change to take effect

Matlab doesn't see .jar file

Ok, I'm stumped here. I'm using Matlab version 2013b with a Java RTE of 1.7.0_11 and I'm trying to run a simple piece of code to see if Matlab is able to read the .jar file and nothing seems to be working.
Here is the Java code, which is compiled to a .jar named JavaOCT.jar, which is placed in the Matlab working directory:
package VTK;
public class vtkVolumeView{
public int Test(){
return 10;
}
}
That is it, no other dependencies, nothing fancy. In Matlab, I try:
javaaddpath('\JavaOCT.jar'); %<-Directory and name are 100% correct
import VTK.*; %<-Package name from above
methodsview VTK.vtkVolumeView; %<-Can't find the class, argh!
Matlab kicks back that it can't find the class.
Things I've done to try and solve the problem:
Reverted to the exact same JDK as the Matlab RTE
Tried an older 1.6 JDK
Done lots of stack overflow research to try and solve it 1 2 3 4
Tried used javaclasspath and pointing to the compiled class instead
Read the Matlab documentation 5
Using clear -java after the javaaddpath
Any help would be appreciated, it is driving me nuts!
Update: Daniel R suggested just javaaddpath('JavaOCT.jar') which doesn't work either.
Final update: It finally works! I wasn't building the .jar properly. In IntelliJ, click on the project and hit F4. This brings up the Project Structure, then go to Artifacts and click the green + button and add DirectoryContent and then point to the out\production. Once this is done, as mentioned by others, it should show up in Matlab as an expandable .jar.
I don't know which operating system you are using, but the ./ seems invalid.
Try javaaddpath('JavaOCT.jar'); or javaaddpath(fullfile(pwd,'JavaOCT.jar'));.
What does exist(fullfile(pwd,'JavaOCT.jar')) return?
Some things to try:
Add the class file. When using a package, you need to add the class file in at the host of the package. For example, if your code is here:
\\full\path\to\code\VTK\vtkVolumeView.class
Then use:
javaaddpath('\\full\path\to\code')
I'm still suspicious of your *.jar path. You should usually use absolute paths when adding jar files. Try adding the results of which('JavaOCT.jar')
How did you make your jar file? Does it contain the appropriate directory structure implied by your package declaration?

How to import a java package in Android Studio

I'm new in android, and I want to import the jfftpack to my project in android studio anda i don't know how to import it.
The original code was import ca.uol.aig.realdoublefft and I'don't know where to put the java files. I've tried to put them to a libs folder.
here's the jfftpack source code:
If it's an existing code library, I'd recommend adding a module for it. Probably the easiest way is to use the File menu command to add a new module, let it create a plain Java (non-Android) module for you, remove the sample class it puts into the module, and then copy your files over into it and tweak it. The module wizard will take care of setting up the directories and build files for you, and you can look at it later and see what did.
Without pressing Alt + enter to import the Packages?
There is some steps like
1)File --->Settings --from left pane we find editor---->General--->Auto Import
There
Insert imports on paste as ALL not ask
And put check mark for all the Above three Fields
1)Show import popup
2)Optimize the imports on fly
3)Add unambiguous imports on the fly
Click Apply and ok
Happy Coding......
If you have the sources import them in the src folder. Is the simple thing that you can do.
I suggest you to use the command line rather than Android Studio interface.
If you work on Linux or MacOS, try to copy the package to your working direcotry like:
cp -r PACKAGE_NAME PATH_TO/AndroidStudioProjects/PROJECT_NAME/app/src/main/java/
I am also new and had the same problem. I didn't have the package instruction at the top of the java file package com.example.myapp

JPype Headaches

I've found several instructions on how to import user-built .class and .jar files to JPype, but I seem to be having a lot of trouble getting anything working at all.
What works: I can import standard java stuff and print HELLO WORLD and such.
Some of what I've tried:
I've tried adding -Djava.class.path with the path to a jar containing the relevant class files, to a directory structure containing (several folders down) the relevant .class files, as well as '-Djava.ext.dirs'. I've recompiled and re-installed with a different JVM location. The class I am attempting to instantiate is Outer, public, and has a public constructor.
I'm using Python 2.6.1 on OSX 10.6.
My current test file:
from jpype import *
startJVM(getDefaultJVMPath(), '-Djava.class.path=/Users/gestalt/Documents/msmexplorer_git/msmexplorer/MSMExplorer/build/classes')
java.lang.System.out.println("hello world")
msmexplorer = JPackage('org.joofee.meh.msmexplorer')
T = msmexplorer.MSMExplorer()
shutdownJVM()
If I use JClass I always get ClassNotFound exceptions from JPype; if I use JPackage I get Package not callable errors. Basically, JPype can't find my stuff.
Thanks so much!
EDIT (possibly helpful debugging stuff...):
Is there a straightforward way to print which third party java classes are available/imported?
Package not callable errors are referenced in this link) it would seem you need to make sure the java class file is accessible from the working directory. I am not sure how the jvm classpath comes into play, I would have thought how you did it would work.
You could also try loading the org package and then getting to the other packages through that one as the link I shared shows:
msmexplorer = JPackage('org').joofee.meh.msmexplorer
T = msmexplorer.MSMExplorer()

Categories

Resources