1

私はJNI4netを使用していますが、ビルドパスにインストールされたライブラリとEclipseはそれらを認識しますが、それでも実行時エラーが発生します。なぜそれがあなたの意見にあるのでしょうか? これがコードです。

 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();
        }
    }

そして、これが私が受け取るメッセージです!

    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)
4

1 に答える 1

1

あなたの人生を楽にするために、ここで私の発見を共有します。私の質問に対する Martin Serrano の回答を読んでください。何をする必要があるかを理解するのに役立ちます。次に、jni4net の Web サイトにアクセスして、サンプルの zip フォルダーをダウンロードします。それを抽出します。myCSharpDemoCalc という例があります。dll を myCSharpDemoCalc.dll (作業フォルダー内) に置き換えてから、generateProxies.cmd (このファイルを編集して dll 名にすることを忘れないでください) と run.cmd を実行します。次に、作業フォルダーに移動し、build.cmd (名前を編集) を実行して JAR ファイルを作成します。おそらく自分でパスを調整する必要があるj4n.dllを吐き出さないかもしれません。この JAR ファイルを使用します。これは、私にとってサードパーティの dll から JAR ファイルを作成する最も簡単な方法でした。

于 2015-03-02T22:35:51.243 に答える