1

当我运行以下命令在我的 JNI 项目中创建头文件时出现以下错误

   root@bsd-pc1907:/home/sat/KISHORE/kishore workspace/Ivijni/bin/classes/com/ivi/jni# javah JniActivity
   error: cannot access JniActivity
   bad class file: RegularFileObject[./JniActivity.class]
   class file contains wrong class: com.ivi.jni.JniActivity
   Please remove or make sure it appears in the correct subdirectory of the classpath.
   com.sun.tools.javac.util.Abort
   at com.sun.tools.javac.comp.Check.completionError(Check.java:180)
   at com.sun.tools.javadoc.DocEnv.loadClass(DocEnv.java:159)
   at com.sun.tools.javadoc.RootDocImpl.<init>(RootDocImpl.java:95)
   at com.sun.tools.javadoc.JavadocTool.getRootDocImpl(JavadocTool.java:188)
   at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:364)
   at com.sun.tools.javadoc.Start.begin(Start.java:162)
   at com.sun.tools.javadoc.Main.execute(Main.java:113)
   at com.sun.tools.javah.Main.main(Main.java:153)
    javadoc: error - fatal error
  2 errors

我的 JniActivity.java

public class JniActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    System.loadLibrary("hellojni");
    new JniActivity().sayHello();

}
private native void sayHello();

}

hellojni.cpp

 #include "hellojni.h"
 #include  <iostream>

 using namespace std;

 void sayHello () {
 cout << "Hello World Again!" << endl;
 return;
 }

任何帮助总是很感激,谢谢

4

1 回答 1

0

root@bsd-pc1907:/home/sat/KISHORE/kishore workspace/Ivijni/bin/classes/com/ivi/jni# javah JniActivity

这里有几个问题。

  1. 您在错误的目录中。你应该在/home/sat/KISHORE/kishore workspace/Ivijni/bin/classes
  2. 您发出错误的命令。javah, javap,rmic和所有其他处理 .class 文件的 Java 实用程序的参数是一个完全限定的类名,包括包名。你没有提供,所以你得到了错误。
于 2013-03-25T09:23:42.130 回答