Sample Code
Sample Code
To access the functionality of the JavaGrinders library you need a Java IDE (i.e., integrated development environment) which allows you to create/edit java source files, to include library files such as the JavaGrinders.lib, and to compile them into Java class files containing platform-neutral Java byte code. There are several free options to choose from, and this page illustrates the steps needed to compile the demo code using the Eclipse Compiler for Java. First download, install and initialize the Eclipse IDE
•Download the ‘Eclipse IDE for Java Developers’ from the Eclipse Foundation website (64 Bit version). The current version is Eclipse Juno (4.2)
•Uncompress the downloaded Eclipse archive and place it into your applications folder
•Open the Eclipse Application. During application startup it asks you to define a workspace for the compiler, essentially a folder on your hard disk that will be used to group your programming efforts together into a single place. Use the suggested default and note where Eclipse is setting-up this workspace.
Download the particular demo you wish to examine. There are demo programs that illustrate how to use different classes of this library.
Sample code for unlocking the tools of the JavaGrinders library
Available Demo Programs
•DataHandlingDemos read and parse data files for use in the JavaGrinders.lib (3 examples).
•PhidgetsDemos interface with USB devices for sensing and control (5 examples).
•PresenterDemos create graphical representations of data, e.g., maps and circular graphs (3 examples).
•VideoProducerDemos create an avi video stream with enhanced reality elements (1 example).
•VisuslStimulusGeneratorDemos create visual stimuli in a window, e.g., moving bars (4 example).
•VideoTrackingDemos extract objects of defined characteristics from a video stream (2 example).
Step by step instructions to use a particular Demo in Eclipse
•The DataHandlingDemos archive illustrates how data files are read and parsed in the JavaGrinders.lib. This archive contains 3 different classes.
•DataHandlingDemo1 - this simple program reads two data columns from a text file and obtains a set of descriptive statistics for them.
•DataHandlingDemo2 - two data columns are read from a text file and displayed in a spreadsheet-like table
•DataHandlingDemo3 - two data columns are read from a text file and descriptive statistics in Y are obtained for subsets defined by ranges of values in X
•Download the DataHandlingDemos, unarchive the folder, and copy the complete folder into your Eclipse’s workspace from above.
•Double click the file DataHandlingDemo1.java < (default package) < src in the Package Explorer on the left side of the window. The java code of the file will display in the center console of the window. With DataHandlingDemo1 selected, click the green ‘Run ...’ button in the top tool bar to execute the code. The results will be display in the lower right console.
Troubleshooting a Demo based on Apple Quicktime in Eclipse
32 vs 64-bit
Apple’s Quicktime media framework and its Java interfaces are no longer supported. They only exists in 32-bit versions and thus every program that utilizes its functions is restricted to running within a 32-bit Java Virtual Machine (JVM). This applies specifically to demo programs for video tracking as both the MovieTracker as well as the SequenceGrabber Demos depend on Quicktime. You will recognize whether you are trying to use a 32-bit Quicktime functions within a 64-bit program if your program fails to execute and the Eclipse console reports the following line:
...
Caused by: java.lang.UnsatisfiedLinkError: /System/Library/Java/Extensions/libQTJNative.jnilib: no suitable image found. ...
...
As recent installs of java default to the 64-bit implementation, you must specify that your application needs to run within the 32-bit JVM. To do this choose “Run Configurations ...” in the “Run” menu and enter “-d32” in the VM Arguments field.
Java HeapSpace
Execution of a java application requires that it has access to a dedicated section of memory for holding and manipulating its variables. In instances where the application runs short of this commodity, it will throw one of several types of runtime errors. Although, commonly such a report will note a shortage of Java Heapspace, a number of other errors may be caused by this problem, such as:
...
java.lang.reflect.InvocationTargetException ...
...
Problems related to insufficient memory resources can be remedied by specifying what amount of RAM is being made available to the JVM with the argument -Xmx128m (for 128 Mbytes) or -Xmx256m (for 256 Mbytes).
Camera Interface
In order to obtain valid video frame data, the software needs to communicate with the camera. If that connection is not being made, the Quicktime library will throw an Exception
...
-9405=couldntGetRequiredComponent ...
...
This arises when no valid source of video frames is available, either no camera is installed/plugged in, a camera is installed but no VDIG component is available to coordinate hardware access, or the camera is being claimed by another program such as iMovie or Quicktime Player.