Code from java examples wont compile

Hey peeps, im trying to get the following code to compile in textpad (if this is a bad environment to use please tell me!)
class BicycleDemo {
public static void main(String[] args) {
// Create two different Bicycle objects
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();
// Invoke methods on those objects
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();
bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
it keeps saying 4 errors, thanks very much

C:\Users\User\Documents\NetBeansProjects\Textpad stuff\BicycleDemo.java:5: cannot find symbol
symbol  : class Bicycle
location: class BicycleDemo
          Bicycle bike1 = new Bicycle();
          ^
C:\Users\User\Documents\NetBeansProjects\Textpad stuff\BicycleDemo.java:5: cannot find symbol
symbol  : class Bicycle
location: class BicycleDemo
          Bicycle bike1 = new Bicycle();
                              ^
C:\Users\User\Documents\NetBeansProjects\Textpad stuff\BicycleDemo.java:6: cannot find symbol
symbol  : class Bicycle
location: class BicycleDemo
          Bicycle bike2 = new Bicycle();
          ^
C:\Users\User\Documents\NetBeansProjects\Textpad stuff\BicycleDemo.java:6: cannot find symbol
symbol  : class Bicycle
location: class BicycleDemo
          Bicycle bike2 = new Bicycle();
                              ^
4 errors
Tool completed with exit code 1

Similar Messages

  • How can i get the source code from java concurrent program in R12

    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    Zulqarnain

    user570667 wrote:
    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    ZulqarnainDid you see old threads for similar topic/discussion? -- https://forums.oracle.com/forums/search.jspa?threadID=&q=Java+AND+Concurrent+AND+Source+AND+Code&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • How to call C/C++ - Code from Java?

    I would like to know if it is possible to call C or C++ - Code from Java and how to do.

    In short, yes you can do this.
    Have a look at http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html
    to see how...
    Good luck!

  • Calling native Objective C code from Java Script

    Hi,
    I want to call native objective C code from Java script.
    I know one way by using : webView:shouldStartLoadWithRequest:navigationType
    Is there another way of doing same?
    Thanks,
    Ganesh Pisal
    Vavni Inc

    Are any of those threads calling java code? If yes then are you calling the Attach method?

  • How to call c++ code from java

    i have a third party dll written in c++. I want to call its methods in java. I searched web and found that I have to use JNI for this. I have seen examples on web writing c++ code and then using it from java through JNI, but can anybody please point to me the example where i have a predefined library or dll in c++ and i have to call it in java. I think that I may have to declare methods in library as native in java and then write a wrapper implementation (dll) in c++ which actually calls the library or dll functions. But, then how will I call methods of dll from my wrapper code.
    Any examples, please point
    Regards,
    Farooq

    There's a JNI forum here that may be a better place for this question; though given the general nature of the question, I suspect that they'll refer you to a tutorial. good luck.

  • Pass return code from Java application to a .bat file.

    I have a .bat file which will execute a Java application. I want to pass the return code from the java application to the ".bat" file.
    Could you please let me know, how can I accomplish this.

    I tried that, but it doesn't return the value...
    In my Java app, I had System.exit(returnCode) and in the '.bat' file
    I have
    @echo off
    java <myApp>
    set returnCd=%?%
    echo %returnCd
    and it didn't return any value. What should I specify in set returnCd=%?% instead of ?

  • Calling c code from java

    hello everyone
    I have question
    I need to call c program from java
    I don't have problem with application or exe file in c it is working but when I call it from java it doesn't work there is no error but it doesn't work because when I execute the c program the black screen must be appeared so that I can enter the input file and then it produces the output file but in java I cann't see the black screen so please can you tell me the problem
    I have used the following code to call c from java:
    String line;  
                   String output1 = "";  
                         Process p = Runtime.getRuntime().exec("cpp.exe");  
                         BufferedReader input = new BufferedReader  
                               (new InputStreamReader(p.getInputStream()));  
                         while ((line = input.readLine()) != null) {  
                               output1 += (line + '\n');  
                         input.close();

    Hi,
    Try this in your code
    p.waitFor();It is for waiting of the process till the completion of the I/O.
    Regards

  • JNI Calling  a multithreaded C code from Java

    Hi,
    I am new to JNI . I am calling a multithreaded C (in which threads are created at runtime )code from a Java application (swing) on some event . The application crashes and it says "pthreads mutex_lock()". I have added -pthread as a command line argument .But even this does not help although the build is proper .It crashes at runtime .All other JNI calls are working perfectly ...
    Please help .
    Thanks in advance ...
    Regards
    Rohit

    Are any of those threads calling java code? If yes then are you calling the Attach method?

  • Running Matlab code from java code

    Ok so I need to make a java gui interface to run Matlab code. After a lot of search I am aware of three approaches,the com.mathworks.jmi package, JNI and i/o streams. So as far as the first approach I cannot find that package nowhereto downlaod, so please if anyone knows where to find it, or why I cannot find it... As far as the second and third approach, I need this to run on both linux and windows so JNI is the only way. So first of all if someone has another approach to suggest, I would like to hear! So I have found code to do this but it is not working and the problem is that there is c code in all this, and my c knowledge is not good at all, so as you have probably understand this is more like a c problem than java, but I'm not completely sure. Anyway I'm posting all the code I use, then the commands I used to compile it and at last the problem.
    Engine.java
    package MatlabNativeInterface;
    import java.io.*;
    * <b>Java Engine for Matlab via Java Native Interface (JNI)</b><br>
    * This class demonstrates how to call Matlab from a Java program via
    * JNI, thereby employing Matlab as the computation engine.
    * The Matlab engine operates by running in the background as a separate
    * process from your own program.
    * <p>
    * Date: 04.04.03
    * <p>
    * Copyright (c) 2003 Andreas Klimke, Universit&#65533;t Stuttgart
    * <p>
    * Permission is hereby granted, free of charge, to any person
    * obtaining a copy of this software and associated documentation
    * files (the "Software"), to deal in the Software without
    * restriction, including without limitation the rights to use, copy,
    * modify, merge, publish, distribute, sublicense, and/or sell copies
    * of the Software, and to permit persons to whom the Software is
    * furnished to do so, subject to the following conditions:
    * <p>
    * The above copyright notice and this permission notice shall be
    * included in all copies or substantial portions of the Software.
    * <p>
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    * OTHER DEALINGS IN THE SOFTWARE.
    * @author W. Andreas Klimke, University of Stuttgart
    *         ([email protected])
    * @version 0.1
    public class Engine {
         * Calls the function <code>engOpen</code> of Matlab's C Engine library.
         * Excerpts from the Matlab documentation:
         * "On UNIX systems, if startcmd is NULL or the empty string,
         * <code>engOpen</code> starts MATLAB on the current host using the
         * command <code>matlab</code>. If startcmd is a hostname, <code>engOpen
         * </code> starts MATLAB on the designated host by embedding the specified
         * hostname string into the larger string:
         * <code>rsh hostname \"/bin/csh -c 'setenv DISPLAY\ hostname:0; matlab'\"
         * </code>. If startcmd is any other string (has white space in it, or
         * nonalphanumeric characters), the string is executed literally to start
         * MATLAB. On Windows, the startcmd string must be NULL."<br>     
         * See the Matlab documentation, chapter "External Interfaces/API
         * Reference/C Engine Functions" for further information.
         * @param startcmd The start command string.
         * @throws IOException Thrown if starting the process was not successful.
      public native void open(String startcmd) throws IOException;
          * Calls the function <code>engClose</code> of Matlab's C Engine
          * library.     This routine allows you to quit a MATLAB engine session.
          * @throws IOException Thrown if Matlab could not be closed.
         public native void close() throws IOException;
         * Calls the function <code>engEvalString</code> of Matlab's C Engine
         * library. Evaluates the expression contained in string for the MATLAB
         * engine session previously started by <code>open</code>.
         * See the Matlab documentation, chapter "External Interfaces/API
         * Reference/C Engine Functions" for further information.
         * @param str Expression to be evaluated.
         * @throws IOException Thrown if data could not be sent to Matlab. This
         *                     may happen if Matlab is no longer running.
         * @see #open
      public native void evalString(String str) throws IOException;
          *  Reads a maximum of <code>numberOfChars</code> characters from
          * the Matlab output buffer and returns the result as String.<br>
          * If the number of available characters exceeds <code>numberOfChars</code>,
          * the additional data is discarded. The Matlab process must be opended
          * previously with <code>open()</code>.<br>
          * @return String containing the Matlab output.
          * @see #open
          * @throws IOException Thrown if data could not be received. This may
          *                     happen if Matlab is no longer running.
      public native String getOutputString(int numberOfChars);
          * Initialize the native shared library.
      static {
             System.loadLibrary("Engine");//I have changed this
         //System.loadLibrary("engineJavaMatlab");
         System.err.println("Native Matlab shared library loaded.");
    }Engine.c
    #include <jni.h>
    #include "MatlabNativeInterface_Engine.h"
    #include <stdio.h>
    #include "engine.h"
    #define DEFAULT_BUFFERSIZE 65536
    Engine* ep;
    char outputBuffer[DEFAULT_BUFFERSIZE];
    JNIEXPORT void JNICALL
    Java_MatlabNativeInterface_Engine_open(JNIEnv *env, jobject obj, const jstring startcmd) {
      const char *c_string = (*env)->GetStringUTFChars(env, startcmd, 0);
      if (!(ep = engOpen(c_string))) {
        jclass exception;
        (*env)->ReleaseStringUTFChars(env, startcmd, c_string);
        exception = (*env)->FindClass(env, "java/io/IOException");
        if (exception == 0) return;
        (*env)->ThrowNew(env, exception, "Opening Matlab failed.");
        return;
      (*env)->ReleaseStringUTFChars(env, startcmd, c_string);
         /* indicate that output should not be discarded but stored in */
         /* outputBuffer */
      engOutputBuffer(ep, outputBuffer, DEFAULT_BUFFERSIZE);
    JNIEXPORT void JNICALL
    Java_MatlabNativeInterface_Engine_close(JNIEnv *env, jobject obj) {
         if (engClose(ep) == 1) {
           jclass exception;
        exception = (*env)->FindClass(env, "java/io/IOException");
        if (exception == 0) return;
        (*env)->ThrowNew(env, exception, "Closing Matlab failed.");
        return;
    JNIEXPORT void JNICALL
    Java_MatlabNativeInterface_Engine_evalString(JNIEnv *env, jobject obj, const jstring j_string) {
      const char *c_string;
         c_string = (*env)->GetStringUTFChars(env, j_string, 0);
      if (engEvalString(ep, c_string) != 0) {
           jclass exception;
        exception = (*env)->FindClass(env, "java/io/IOException");
        if (exception == 0) return;
        (*env)->ThrowNew(env, exception, "Error while sending/receiving data.");
      (*env)->ReleaseStringUTFChars(env, j_string, c_string);
    JNIEXPORT jstring JNICALL
    Java_MatlabNativeInterface_Engine_getOutputString(JNIEnv *env, jobject obj, jint numberOfChars) {
      char *c_string;
         jstring j_string;
         if (numberOfChars > DEFAULT_BUFFERSIZE) {
              numberOfChars = DEFAULT_BUFFERSIZE;
      c_string = (char *) malloc ( sizeof(char)*(numberOfChars+1) );
         c_string[numberOfChars] = 0;
      strncpy(c_string, outputBuffer, numberOfChars);
         j_string = (*env)->NewStringUTF(env, c_string);
         free(c_string);
      return j_string;
    }MatlabNativeInterface_Engine.h (as produced by javah)
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class MatlabNativeInterface_Engine */
    #ifndef _Included_MatlabNativeInterface_Engine
    #define _Included_MatlabNativeInterface_Engine
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     MatlabNativeInterface_Engine
    * Method:    open
    * Signature: (Ljava/lang/String;)V
    JNIEXPORT void JNICALL Java_MatlabNativeInterface_Engine_open
      (JNIEnv *, jobject, jstring);
    * Class:     MatlabNativeInterface_Engine
    * Method:    close
    * Signature: ()V
    JNIEXPORT void JNICALL Java_MatlabNativeInterface_Engine_close
      (JNIEnv *, jobject);
    * Class:     MatlabNativeInterface_Engine
    * Method:    evalString
    * Signature: (Ljava/lang/String;)V
    JNIEXPORT void JNICALL Java_MatlabNativeInterface_Engine_evalString
      (JNIEnv *, jobject, jstring);
    * Class:     MatlabNativeInterface_Engine
    * Method:    getOutputString
    * Signature: (I)Ljava/lang/String;
    JNIEXPORT jstring JNICALL Java_MatlabNativeInterface_Engine_getOutputString
      (JNIEnv *, jobject, jint);
    #ifdef __cplusplus
    #endif
    #endifand a Main.java
    import MatlabNativeInterface.*;
    import java.io.*;
    * Demonstration program for connecting Java with Matlab using the Java
    * Native Interface (JNI). Wrapper functions access Matlab via Matlab's
    * native C Engine library.
    public class Main {
         public static void main(String[] args) {
              Engine engine = new MatlabNativeInterface.Engine();
              try {
                   // Matlab start command:
                   engine.open("matlab -nosplash -nojvm");
                   // Display output:
                   System.out.println(engine.getOutputString(500));
          // Example: Solve the system of linear equations Ax = f with
                   // Matlab's Preconditioned Conjugate Gradients method.
                   engine.evalString("A = gallery('lehmer',10);");  // Define Matrix A
                   engine.evalString("f = ones(10,1);");            // Define vector f
                   engine.evalString("pcg(A,f,1e-5)");              // Compute x
                   // Retrieve output:
                   System.out.println(engine.getOutputString(500));
                   // Close the Matlab session:
                   engine.close();
              catch (Exception e) {
                   e.printStackTrace();
    }so I compile them with:
    javac -d classes @files.txt
    javah -classpath classes MatlabNativeInterface.Engine
    cc -shared -I/usr/java/jdk1.6.0_06/include/ -I/usr/java/jdk1.6.0_06/include/linux/ -I/usr/local/share/matlab7.6/extern/include/ Engine.c -o libEngine.soso everything gets compiled well and then I run Main:
    /javas/classes/_>mv libEngine.so classes/
    /javas/classes/_>cd classes/
    /javas/classes/_>java -Djava.library.path=. Main
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /javas/classes/libEngine.so: /javas/classes/libEngine.so: undefined symbol: engOpen
            at java.lang.ClassLoader$NativeLibrary.load(Native Method)
            at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
            at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
            at java.lang.Runtime.loadLibrary0(Runtime.java:823)
            at java.lang.System.loadLibrary(System.java:1030)
            at MatlabNativeInterface.Engine.<clinit>(Engine.java:99)
            at Main.main(Main.java:11)So... please help!

    I need this to run on both linux and windows so JNI is the only wayHuh? Streams in general work on windows and linux. So maybe some more specific info
    about what you mean by "i/o streams."
    I am aware of three approachesA fourth approach is to write an application in C which communicates with Matlab directly
    and then uses some idiom such as sockets to allow communication to java. This would generally
    be the method that I would prefer over all others since it makes debugging and testing easier.
    undefined symbol: engOpenSomehow you are missing a library (nothing specific to to with JNI nor java) in you JNI code.
    Odd error since I would normally expect something else. Try using System.load/loadLibrary() in java to explicitly load the Matlab
    library (or libraries) before your JNI library. The load/LoadLibrary calls don't care if it is JNI or not.

  • Call c++ from Java - Example

    Dear friends,
    does there exist some examples of JNI that demonstrates to call
    java from c++ program?
    Thanks you very much.
    Anil

    Hi there!
    Maybe this can help?
    http://www.jovial.com/javaAndCpp/java_and_cpp.html
    Good Luck!
    FroyBirte

  • How to get exit code from C code when calling java method via JNI?

    Hi, All
    in my project, i need to call a java method from C code using JNI, yet I do
    not know how to
    retrieve the exit code of java program. the java code is like below
    public static void main(....)
    if(error){
    System.exit(-77);// the exit code is -77
    and the JNI c code may like below
    /* Invoke main method. */
        (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);
    //here I want to retrieve the exit code from java to check if there is an
    error
    any suggestions? thanks

    Hi Liang Zhang,
    In your C code add:
    void (JNICALL y_exit)(jint code) {
    and when you are initialazing JVM options add:
    JavaVMOption options[...];
    options[...].optionString = "exit";
    options[...].extraInfo    = y_exit;
    See http://java.sun.com/j2se/1.3/docs/guide/jni/jni-12.html
    Best regards, Maksim Rashchynski.

  • Generate IDL from Java Code, Classes, UML, etc?

    Hi,
    is is possible to generate IDL code from Java Code, Classes, UML, ... using JDeveloper?
    I know this is somewhat reverse engeneering, but it would speed up the migration of our existing Java project...
    Thanks,
    Johan

    Hi,
    is is possible to generate IDL code from Java Code, Classes, UML, ... using JDeveloper?
    I know this is somewhat reverse engeneering, but it would speed up the migration of our existing Java project...Unfortunately it does not. The IDL to Java conversion is handled under the covers by the idl2java.exe included with the database. You might want to search on google for a IDL generator from java source.
    java2iiop (another tool) just generates IIOP stubs from classes and interfaces, but I don't think it creates IDL.
    Rob

  • Problem calling two perl modules from java in seperate threads(JVM CRASHES)

    Dear Friends,
    I have one severe problem regarding calling perl modules from java
    I had to call two perl modules simultaneously (i.e.) from two threads,,, but jvm crashes when one of the perl calls is exiting earlier
    I am unable to spot out why ....
    For calling perl from java ...., We are first calling C code from java using JNI and then Perl code from C
    All works fine if we call only one perl call at a time.... If we call them in a synchronized manner the JVM is not crashing .... But we don't want blocking..
    The following is the code snippet
    <JAVA FILE>
    class Sample
         static {
              System.loadLibrary("xyz");  // Here xyz is the library file generated by compiling c code
         public native void call_PrintList();
         public native void call_PrintListNew();
         Sample()
              new Thread1(this).start();     
         public static void main(String args[])
              System.out.println("In the main Method");
              new Sample().call_PrintList();
         class Thread1 extends Thread
              Sample sample;
              Thread1(Sample sam)
                   sample=sam;
              public void run()
                   sample.call_PrintListNew();     
    }<C FILE>
    #include <EXTERN.h>
    #include <perl.h>
    static PerlInterpreter *my_perl;
    static char * words[] = {"alpha", "beta", "gamma", "delta", NULL } ;
    static void
    call_PrintList(){
         printf("\nIn the Call method of string.c\n");
            char *wor[] = {"hello", "sudha", NULL } ;
               char *my_argv[] = { "", "string.pl" };
               PERL_SYS_INIT3(&argc,&argv,&env);
               my_perl = perl_alloc();
                   PL_perl_destruct_level = 1; //// We have mentioned this also and tried removing destruct call
               perl_construct( my_perl );
               perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
              PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
               perl_run(my_perl);
         dSP ;
            perl_call_argv("PrintList",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
    //     perl_destruct(my_perl);
    //          perl_free(my_perl);
    //           PERL_SYS_TERM();
    static void
    call_PrintListNew(){
    printf("In the new call method\n");
    char *wor[] = {"Hiiiiiiiiiiiiiii", "Satyam123333", NULL } ;
            char *my_argv[] = { "", "string.pl" };
            PERL_SYS_INIT3(&argc,&argv,&env);
            my_perl = perl_alloc();
    PL_perl_destruct_level = 1;
            perl_construct( my_perl );
            perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
            perl_run(my_perl);
            dSP ;
            perl_call_argv("PrintListNew",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
      //      perl_destruct(my_perl);
      //      perl_free(my_perl);
       //     PERL_SYS_TERM();
    void callNew()
    call_PrintListNew();
    void call ( )
    call_PrintList();
    //char *wor[] = {"hello","sudha",NULL};
    /*   char *my_argv[] = { "", "string.pl" };
          PERL_SYS_INIT3(&argc,&argv,&env);
          my_perl = perl_alloc();
          perl_construct( my_perl );
          perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
         PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
          perl_run(my_perl);*/
       //   call_PrintList();                      /*** Compute 3 ** 4 ***/
    /*      perl_destruct(my_perl);
          perl_free(my_perl);
          PERL_SYS_TERM();*/
        }And Finally the perl code
    sub PrintList
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
    sub PrintListNew
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
            }Please help me in this regard

    Dear Friends,
    I have one severe problem regarding calling perl modules from java
    I had to call two perl modules simultaneously (i.e.) from two threads,,, but jvm crashes when one of the perl calls is exiting earlier
    I am unable to spot out why ....
    For calling perl from java ...., We are first calling C code from java using JNI and then Perl code from C
    All works fine if we call only one perl call at a time.... If we call them in a synchronized manner the JVM is not crashing .... But we don't want blocking..
    The following is the code snippet
    <JAVA FILE>
    class Sample
         static {
              System.loadLibrary("xyz");  // Here xyz is the library file generated by compiling c code
         public native void call_PrintList();
         public native void call_PrintListNew();
         Sample()
              new Thread1(this).start();     
         public static void main(String args[])
              System.out.println("In the main Method");
              new Sample().call_PrintList();
         class Thread1 extends Thread
              Sample sample;
              Thread1(Sample sam)
                   sample=sam;
              public void run()
                   sample.call_PrintListNew();     
    }<C FILE>
    #include <EXTERN.h>
    #include <perl.h>
    static PerlInterpreter *my_perl;
    static char * words[] = {"alpha", "beta", "gamma", "delta", NULL } ;
    static void
    call_PrintList(){
         printf("\nIn the Call method of string.c\n");
            char *wor[] = {"hello", "sudha", NULL } ;
               char *my_argv[] = { "", "string.pl" };
               PERL_SYS_INIT3(&argc,&argv,&env);
               my_perl = perl_alloc();
                   PL_perl_destruct_level = 1; //// We have mentioned this also and tried removing destruct call
               perl_construct( my_perl );
               perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
              PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
               perl_run(my_perl);
         dSP ;
            perl_call_argv("PrintList",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
    //     perl_destruct(my_perl);
    //          perl_free(my_perl);
    //           PERL_SYS_TERM();
    static void
    call_PrintListNew(){
    printf("In the new call method\n");
    char *wor[] = {"Hiiiiiiiiiiiiiii", "Satyam123333", NULL } ;
            char *my_argv[] = { "", "string.pl" };
            PERL_SYS_INIT3(&argc,&argv,&env);
            my_perl = perl_alloc();
    PL_perl_destruct_level = 1;
            perl_construct( my_perl );
            perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
            perl_run(my_perl);
            dSP ;
            perl_call_argv("PrintListNew",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
      //      perl_destruct(my_perl);
      //      perl_free(my_perl);
       //     PERL_SYS_TERM();
    void callNew()
    call_PrintListNew();
    void call ( )
    call_PrintList();
    //char *wor[] = {"hello","sudha",NULL};
    /*   char *my_argv[] = { "", "string.pl" };
          PERL_SYS_INIT3(&argc,&argv,&env);
          my_perl = perl_alloc();
          perl_construct( my_perl );
          perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
         PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
          perl_run(my_perl);*/
       //   call_PrintList();                      /*** Compute 3 ** 4 ***/
    /*      perl_destruct(my_perl);
          perl_free(my_perl);
          PERL_SYS_TERM();*/
        }And Finally the perl code
    sub PrintList
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
    sub PrintListNew
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
            }Please help me in this regard

  • UnsatisfiedLinkError - Trying to access a DLL from Java

    I am trying to use the Java Native Interface (JNI) to run some C++ code from Java. I tried a simple test program to teach myself that, and it worked perfectly. However, now that I'm tackling a bigger project (A data acquisition program), I get an UnsatisfiedLinkError in the line that calls the function from the DLL.
    Here is the stacktrace: Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.Invoca
    tionTargetException
            at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAc
    tion.java:859)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(App
    licationAction.java:665)
            at org.jdesktop.application.ApplicationAction.actionPerformed(Applicatio
    nAction.java:698)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
    95)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
    a:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
    java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(App
    licationAction.java:662)
            ... 26 more
    Caused by: java.lang.UnsatisfiedLinkError: fileiotest.dllinterface.startget()V
            at fileiotest.dllinterface.startget(Native Method)
            at fileiotest.dllinterface.start_daq(dllinterface.java:26)
            at fileiotest.FileIOTestView.startrun(FileIOTestView.java:680)
            ... 31 moreI have made sure that the DLL is in the classpath, using both the -classpath tag and by setting the PATH variable. Is something wrong with my DLL itself, perhaps?

    Yes, I have.
    I didn't include the code yet because I thought if someone had similar trouble, there might be something obvious I am overlooking and they wouldn't even need to see the code. I can provide it, however.
    This is the C++ DLL
    // consoledaq.cpp : Defines the entry point for the console application.
    #include <windows.h>                    /* Compiler's include files's */
    #include <string.h>                  
    #include <stdio.h>
    #include "cbw.h"
    #include "stdafx.h"
    #include "dllinterface.h"
    #include "jni.h" //can copy or give full path
    #include <math.h>
    BOOL APIENTRY DllMain( HANDLE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
        return TRUE;
    #define BOARD_NUM      0                /* Number of A/D board as defined with InstaCal */
    #define BUF_SIZE       10048            /* Size of buffer */
    #define NUM_SECS       10                /* Number of secs to collect data */
    #define ADRANGE        BIP5VOLTS        /* A/D voltage range */
    #define TIMER_NUM      1                /* Windows timer used by this program */
    static HGLOBAL  MemHandle32;       
    /* Variables for AinScan */
    static unsigned short *ADValues;    /* Win32 pointer to A/D buffer */
    static HGLOBAL   ADMemHandle;
    static short     ADCurStatus;       /* Current status for D/A scan */
    static long      ADCurCount;        /* Current count for A/D scan  */
    static long      ADCurIndex;        /* Current index for A/D scan  */
    int              ADOptions;
    long       Count, Rate;
    float      Voltage, Voltage2;
    unsigned short CurValue, CurValue2;
    JNIEXPORT void JNICALL
    Java_daq_startget(JNIEnv *env, jobject obj)
         cbErrHandling (PRINTALL, STOPALL);  /* Set library's error handling */
         ADCurStatus = RUNNING;
         ADCurIndex = 0l;
         ADCurCount = 0l;
         /* Allocate A/D Windows buffer */
         ADMemHandle = cbWinBufAlloc ((long)BUF_SIZE);
         /* Allocate a local WIN32 buffer to hold A/D Data */
         MemHandle32 = GlobalAlloc(GMEM_FIXED | GMEM_DDESHARE, BUF_SIZE *sizeof(short));
         /* Get a 32-bit pointer to the A/D WIN32 buffer */
         ADValues = (unsigned short *)GlobalLock(MemHandle32);
         /* Start up background A/D scan */
         Count = BUF_SIZE;
         Rate = BUF_SIZE / (NUM_SECS * 2);
         ADOptions = BACKGROUND | CONTINUOUS;
         cbAInScan (BOARD_NUM, 0, 1, Count, &Rate, ADRANGE, ADMemHandle, ADOptions);
    JNIEXPORT void JNICALL
    Java_daq_stopget(JNIEnv *env, jobject obj)
         cbStopBackground(BOARD_NUM, AIFUNCTION);  /* Stop A/D subsystem background scan */
         if (ADMemHandle)                 
              cbWinBufFree (ADMemHandle);   /* Free allocated memory */
         if (MemHandle32)
              GlobalFree (MemHandle32);
    JNIEXPORT jfloatArray JNICALL
    Java_daq_getpoint(JNIEnv *env, jobject obj)
         jfloatArray theArray;
         if (ADCurIndex >= 0)
              /* Copy Data from memory to 32 bit memory buffer */
              cbWinBufToArray(ADMemHandle, &ADValues[ADCurIndex], ADCurIndex ,2);
              CurValue = ADValues[ADCurIndex];
              CurValue2 = ADValues[(ADCurIndex + 1)];
         else
              CurValue = 0;
              CurValue2 = 0;
         jfloat tmp[2];
         theArray =  env->NewFloatArray(2);
         cbToEngUnits(BOARD_NUM,ADRANGE,CurValue,&Voltage);                      
         cbToEngUnits(BOARD_NUM,ADRANGE,CurValue2,&Voltage2);
         tmp[0] = Voltage;
         tmp[1] = Voltage2;
         env->SetFloatArrayRegion(theArray, 0, 2, tmp);
         return theArray;
    }And this is the Java class:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package fileiotest;
    * @author Owner
    public class dllinterface {
        public native void startget();
        public native float[] getpoint();
        public native void stopget();
        static {
         System.loadLibrary("daqdll");//This is firstJNI.DLL
         /*if generated by borland
         System.loadLibrary("firstjni");//This is firstjni.dll
        public static void start_daq()
            dllinterface DI=new dllinterface();
            DI.startget();
        public static void stop_daq()
            dllinterface DI=new dllinterface();
            DI.stopget();
        public static float[] get_data_point()
          dllinterface DI=new dllinterface();
          float newtempfloat[];
          newtempfloat = DI.getpoint();
          return newtempfloat;
    }

  • Cannot reach com.sun.javafx.runtime.sequence package from Java

    Hello!
    I'm trying to create JavaFX sequence from Java code, because creating sequences with large amount of data (more than 10000 elements) seems to be quite inefficient in JavaFX (leastwise takes almost a minute(!) when using insert ... into ...).
    The problem is that I get the following error message when trying to use SequenceBuilder from Java:
    {color:#ff0000}+Compiling 1 source file to C:\Users\&Aacute;kos\Documents\NetBeansProjects2\PolylineProba\build\classes+
    C:\Users\&Aacute;kos\Documents\NetBeansProjects2\PolylineProba\src\polylineproba\ArrayBuilder.java:11: package com.sun.javafx.runtime.sequence does not exist
    import com.sun.javafx.runtime.sequence.*;
    +1 error+{color}
    The sample code is very simple:
    {color:#333399}+package test;+
    import com.sun.javafx.runtime.sequence.*;
    +public class ArrayBuilder {+
    +}+{color}
    This is strange as the code completion sees all classes inside the mentioned package, but the compiler doesn't.
    Does anyone have an idea, why? (I'm using Netbeans 6.1 with JavaFX SDK preview 1.0.)
    Thanks,
    Akos

    Hello!
    Normally you don't need to know the exact location of these files as you can add them to the project by adding a library. To do this in Netbeans: right click on the Libraries in the project tree and choose Add library. Then you should see JavaFXUserLib.
    If not then find and add them manually to the classpath:
    javafx-sdk1.0pre1/lib/Decora-D3D.jar
    javafx-sdk1.0pre1/lib/Decora-HW.jar
    javafx-sdk1.0pre1/lib/Decora-OGL.jar
    javafx-sdk1.0pre1/lib/Scenario.jar
    javafx-sdk1.0pre1/lib/gluegen-rt.jar
    javafx-sdk1.0pre1/lib/javafx-swing.jar
    javafx-sdk1.0pre1/lib/javafxc.jar
    javafx-sdk1.0pre1/lib/javafxdoc.jar
    javafx-sdk1.0pre1/lib/javafxgui.jar
    javafx-sdk1.0pre1/lib/javafxrt.jar
    javafx-sdk1.0pre1/lib/jmc.jar
    javafx-sdk1.0pre1/lib/jogl.jar
    Good luck

Maybe you are looking for