Issue Exporting .app Using Processing and Leap Motion SDK - java

I have been trying to export a standalone application for Mac using the "Export Application" function in Processing. The simple application, which involves updating a float value on the screen that corresponds to the y-axis position of a hand detected by a Leap Motion, works perfectly well within Processing. However, once I export the application and try to run it, the app opens for a brief second and quickly closes. I have exported applications from Processing successfully before, but not one that uses the Leap SDK. I am using the LeapMotion library for Processing to access the Leap SDK: https://github.com/heuermh/leap-motion-processing. Here is my code:
import processing.core.*;
import com.leapmotion.leap.processing.*;
import com.leapmotion.leap.Controller;
import com.leapmotion.leap.Listener;
public class Test extends PApplet {
Controller controller;
MyListener listener;
float position = 0.0f;
class MyListener extends Listener {
public void onFrame(Controller controller) {
if (!controller.frame().hands().isEmpty()) {
position = controller.frame().hands().leftmost().palmPosition().get(1);
}
}
}
public void setup() {
size(600,600);
controller = new Controller();
listener = new MyListener();
controller.addListener(listener);
}
public void draw() {
background(0);
textAlign(CENTER,CENTER);
textSize(50);
text(position, 300,300);
}
public static void main(String args[]) {
PApplet.main("Test");
}
}
When I export the application, the contents of the application are as follows:
Info.plist
Java
-core.jar
-gluegen-rt-natives-macosx-universal.jar
-gluegen-rt.jar
-jogl-all-natives-macosx-universal.jar
-jogl-all.jar
-LeapJava.jar
-LeapMotion.jar
-libLeap.dylib
-libLeapJava.dylib
-Test.jar
MacOS
-Test
Plugins
-jdk1.7.0_45.jdk
Resources
-en.lproj
-sketch.icns
PkgInfo
Any help would be greatly appreciated!
P.S. I've already tried bundling the program into a runnable JAR file.

Related

(Android Unity plugin) i created a simple plugin, expected 123, got 0

I'm trying to make a plugin for Unity, but not even the simplest class works.
In Android Studio I created a library module, and in it, the following class:
package com.vuforia.android.pluginlib;
import static android.os.Looper.getMainLooper;
public class Multi {
static public Multi mult=new Multi();
static public int testes =123;
}
After that I added to the gradle of lib, the following configurations of a Task,to create the aar:
task copyPlugin (type : Copy){
dependsOn assemble
from ('build/outputs/aar')
into ('../../Assets/Plugins/Android')
include(project.name+'-release.aar')
}
In unity, I created some sprite, and added such script to it:
using UnityEngine;
public class movetest : MonoBehaviour
{
private AndroidJavaClass javaClass = null;
void Update()
{
javaClass = new AndroidJavaClass("com.vuforia.android.pluginlib.Multi");
int i = javaClass.GetStatic<int>("testes");
Debug.Log("->>"+i);
}
}
and when clicking on run, then what is received "- >>0".
I assume you are running in the editor because you stated "when clicking on run"..
Java plugins will not work in the editor. You would need to deploy to an Android device to test the functionality.

how to detect android studio file modification events

I need to visualize how a project develops over time.
I have used this: https://docs.oracle.com/javase/tutorial/essential/io/notification.html#overview
as basis for detecting when any project file has been modified locally.
The current setup is Android Studio on windows 7. And my problem is that the java.nio.file.StandardWatchEventKinds from the example only gets fired when the programmer manually does a "ctrl-s".
How do I detect Android Studios file modifications realtime?.
My fallback approach is to to set a timer an traverse all files. But i'd rather if I could just catch the appropriate file.
EDIT: solved with an IntelliJ plugin, took me 1/2 day.
first the tutorial from: https://confluence.jetbrains.com/display/IDEADEV/Getting+Started+with+Plugin+Development#GettingStartedwithPluginDevelopment-anchor3
and using the menuaction to start/stop a BulkFileListener:
public class Watcher implements BulkFileListener {
private final MessageBusConnection connection;
public Watcher() {
connection = ApplicationManager.getApplication().getMessageBus().connect();
}
public void initComponent() {
connection.subscribe(VirtualFileManager.VFS_CHANGES, this);
}
public void disposeComponent() {
connection.disconnect();
}
#Override
public void before(List<? extends VFileEvent> events) {
//logging done
}
#Override
public void after(List<? extends VFileEvent> events) {
//logging done
}
}
placed the . jar in ...\JetBrains\IntelliJ IDEA Community Edition 14.1.3\plugins
and imported as instructed in the tutorial.

Why can't I run the all java classes?

I'm doing a port over of codes from Processing to Netbeans Java. I'm having problems running multiple java classes. My codes are spread out into 14 classes, where my main class include only this set of codes:
package gardeningmania;
import java.io.File;
import processing.core.*;
public class GardeningMania extends PApplet{
public static void main(String[] passedArgs) {
File currentDir = new File("."); getAllFilse(currentDir);
PApplet.main(new String[]{/*"--present",*/"gardeningmania.GardeningMania"});
}
public static void getAllFilse(File currentDir) {
File[] filesList = currentDir.listFiles();
for(File f : filesList){
if(f.isDirectory()) getAllFilse(f);
if(f.isFile()){ System.out.println(f.getName()); }
}
}
}
Whenever the project is being run, only a small screen will pop-up with a gray background, however, that's all it shows. It seems to me that it's unable to read all my codes from the other 13 classes. Any ideas, anyone?
Applets don't use a main()-method; you have to implement other Methods instead:
void init();
void start();
void stop();
void destroy();
By default, the class Applet doesn't implement them, they all have only an empty block.
Please see:
Why do applets not need a main()?
Java Applet runs without a main method?
Lesson: Java Applets
Life Cycle of an Applet

JavaExe and Java application as windows system service interactive to desktop

Request:
This is a very common problem faced by Java devs in my locale. I am really stuck for many days on this. Searched and tried a lot, read the docs. read ALL the stackoverflow questions related to JavaExe. Please only reply if you have done similar thing before and have a comprehensive answer. I would be really grateful to the community!
Senario:
I am using JavaExe to run an application as system service in desktop interactive capability.
To be exact I have an application that captures screenshots of desktops. I want it to run (as admin) on any user login so no one can stop it.
I have a myapp.jar, settings.txt and a lib dir.
I have searched alot and found JavaExe works (by watching its examples)
If anyone has a better way. Please state so.
Problem:
According to my research,
you must create a .properties file that has named like the .exe, and write "RunType = 1" in this file.
you define a static method in your main class : serviceInit()
Do I need to place any class or reference/import? How?
Edit:
My code below works as stand alone .jar and in javaExe.exe too.
It now does makes a system service and runs by as SYSTEM user. but It is NOT interactive to desktop. i.e its not showing any GUI.
package temp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Temp {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
serviceInit();
}
public static boolean serviceInit(){
new Thread(){
public void run(){
Integer i = 0;
while(i < 999999999){
JOptionPane.showMessageDialog(null,i);
i++;
}
}
}.start();
return true;
}
}
And I dont think that bundling the .jar, lib directory and settings.txt into one .exe is possible?
you should have in your case :
public class MyApp_ServiceManagement
{
static boolean isMsgToDisplay = false;
/////////////////////////////
public static boolean serviceInit()
{
(new Thread()
{
public void run()
{
for(int i=0;i < 6;i++)
{
try { sleep(5*1000); }
catch(Exception ex) {}
isMsgToDisplay = true;
}
}
}).start();
return true;
}
/// is Data ready to be send to the UI ?
public static boolean serviceIsDataForUI()
{
return isMsgToDisplay;
}
/// Data to be send to the UI
public static Serializable serviceDataForUI()
{
isMsgToDisplay = false;
return "hello, I am an interactive Service";
}
}
and for the UI part :
public class MyApp_TaskbarManagement
{
/// To show (or not) the icon in tray
public static boolean taskIsShow()
{
return false;
}
/// Receive the message from Service
public static void taskDataFromService(Serializable data)
{
JOptionPane.showMessageDialog(null, data);
}
/// descr of UI
public static String[] taskGetInfo()
{
return new String[]
{
"UI part of Service"
};
}
}
the main() method is never called in service mode (except one particular case), but if you want keep your main() method you must put a call to main() in serviceInit().
Put serviceInit() in your main class or in another class named XXX_ServiceManagement where XXX is the name of your main class.
Then, serviceInit() must return before a 30 seconds delay.
Don't put a infinite loop, ... in it.
Put your code in a thread, and start it from serviceInit() (or main)
That answer to your problem?

Loading image in Java J2ME

I have a problem with loading image with java 2ME. I have a image file "picture.png" in location drive "C:". After that I wrote my like this to show image from this location.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class ImageMidlet extends MIDlet implements CommandListener{
private Display display;
private Command exitCommand;
private Command backCommand;
private Command okCommand;
private Form form;
private ImageItem imageItem;
private Image image;
public ImageMidlet(){
display = Display.getDisplay(this);
form=new Form("");
exitCommand = new Command("Exit", Command.EXIT, 1);
backCommand = new Command("Back", Command.BACK, 2);
okCommand = new Command("OK", Command.OK, 3);
try {
image=Image.createImage("/picture.png");
imageItem=new ImageItem(null,image,ImageItem.LAYOUT_NEWLINE_BEFORE,"");
}
catch(IOException ex){
}
form.append(imageItem);
form.addCommand(okCommand);
form.addCommand(exitCommand);
form.addCommand(backCommand);
form.setCommandListener(this);
display.setCurrent(form);
}
public void commandAction(Command c,Displayable d){
}
public void startApp() {
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
It shows me this error:
Unable to create MIDlet Test.ImageMidlet
java.lang.NullPointerException
at javax.microedition.lcdui.Form.append(Form.java:638)
at Test.ImageMidlet.<init>(ImageMidlet.java:39)
at java.lang.Class.runCustomCode(+0)
at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
at com.sun.midp.midlet.Selector.run(Selector.java:151)
I am starting learn to develop, so please guide to do this.
Image.createImage(String name) loads the given image as a resource. Resources are loaded with Class.getResourceAsStream(name), which looks up the resources from classpath, not from your file system root.
You should put the image file in your classpath, which is usually the final application .jar file. Usually a folder called resources or res is created under the project, where the images are placed. The contents of this folder are then copied to the .jar file. In development phase you should be able to append your resource folder to the classpath with a command-line parameter (java -cp resources in Java SE) or with a similar IDE setting.
If you are really interested in loading the images from actual file system, you can use optional FileConnection API (http://developers.sun.com/mobility/apis/articles/fileconnection/). The handset support for this API is limited though. For static images the classpath is the way to go.
As msell said - You can't access images from Your computer. Make sure that You have included the given image in midlet jar file. If You try to access it using '/picture.png', then it should be located a the root directory in jar.
First of all place your image in default package.
I have placed "My Network Places.png" in default package.
Then create MIDlet named "ImageItemExample"
then copy below code in that MIDlet file.
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ImageItemExample extends MIDlet implements CommandListener{
private Display display;
private Command exit;
private Form form;
private ImageItem logo;
public ImageItemExample(){
form = new Form("Image Item");
exit = new Command("Exit", Command.EXIT, 0);
try{
logo = new ImageItem(null, Image.createImage("/My Network Places.png"),
ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_BEFORE |
ImageItem.LAYOUT_NEWLINE_AFTER, "Roseindia");
form.append(logo);
}catch(IOException e){
form.append(new StringItem(null, "Roseindia: Image not available: "+ e));
}
}
public void startApp(){
display = Display.getDisplay(this);
form.addCommand(exit);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command c, Displayable d){
String label = c.getLabel();
if(label.equals("Exit")){
destroyApp(true);
}
}
}
My guess is that
image=Image.createImage("/picture.png");
throws an exception which prevents the creation of a new object of type ImageItem which leaves your imageItem variable as null. This gives you the null pointer exception.
Isn't your file Picture.png and not Pictur.png?
Verify that the file picture.png actually exists
depending on the device emulator/IDE there should be a way to set the "HOME" directory for the device. In your case, this would be "C:\"

Categories