Pejman Saberin
Pejman Saberin

Reputation: 69

Exception in thread "main" java.lang.Error: Unresolved compilation problems: JNI4net

I am working with JNI4net and although the libraries and installed in the build path and eclipse recognizes them, it still gives me run time error. Why could that be in your opinion? Here is the code.

 import net.sf.jni4net.*;

import java.io.IOException;
import java.lang.String;

import system.*;
import system.Object;
import system.io.TextWriter;
import system.collections.IDictionary;
import system.collections.IEnumerator;

    /**
     * @author Pavel Savara (original)
     */
    public class Program {
        public static void main(String[] args) throws IOException {
            // create bridge, with default setup
            // it will lookup jni4net.n.dll next to jni4net.j.jar 
            //Bridge.setVerbose(true);
            Bridge.setVerbose(true);
            Bridge.init();

            // here you go!
            Console.WriteLine("Hello .NET world!\n");

            // OK, simple hello is boring, let's play with System.Environment
            // they are Hashtable realy
            final IDictionary variables = system.Environment.GetEnvironmentVariables();

            // let's enumerate all keys
            final IEnumerator keys = variables.getKeys().GetEnumerator();
            while (keys.MoveNext()) {
                // there hash table is not generic and returns system.Object
                // but we know is should be system.String, so we could cast
                final system.String key = (system.String) keys.getCurrent();
                Console.Write(key);

                // this is automatic conversion of JVM string to system.String
                Console.Write(" : ");

                // we use the hashtable
                Object value = variables.getItem(key);

                // and this is JVM toString() redirected to CLR ToString() method
                String valueToString = value.toString();
                Console.WriteLine(valueToString);
            }

            // Console output is really TextWriter on stream
            final TextWriter writer = Console.getOut();
            writer.Flush();
        }
    }

AND here is the message I get!

    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Bridge cannot be resolved
    Bridge cannot be resolved
    Console cannot be resolved
    IDictionary cannot be resolved to a type
    system cannot be resolved
    IEnumerator cannot be resolved to a type
    system cannot be resolved to a type
    system cannot be resolved to a type
    Console cannot be resolved
    Console cannot be resolved
    Console cannot be resolved
    TextWriter cannot be resolved to a type
    Console cannot be resolved

    at Program.main(Program.java:37)

Upvotes: 1

Views: 1096

Answers (1)

Pejman Saberin
Pejman Saberin

Reputation: 69

To make your life easier, I am going to share my findings here. Read Martin Serrano's answer to my question. It will help you understand what needs to be done. Then go to jni4net's website and download their example zip folder. Extract that. There is an example there called myCSharpDemoCalc. Replace your dll with myCSharpDemoCalc.dll (inside work folder) and then run generateProxies.cmd (be sure to edit this file to your dll name) and run.cmd. Then go to the work folder and run build.cmd (edit name) to create your JAR file. It might not spit out the j4n.dll you probably need to twik the path yourself. Use this JAR file. This was the easiest way to create a JAR file from a third party dll for me.

Upvotes: 1

Related Questions