Javah error: Could not find class file for ' XX ' or exception in thread ' main ' Name:XX.class

Source: Internet
Author: User

When Java uses JNI, it uses the header file of Javah genetic. h, but the file is not found with an error.

You may open the directory, clearly see a class file is the error can not find the file, because Javah to find the class package name first. What does that mean.

On the source code bar.

If you have one of these Java classes:

public class hello{public
    static native string init (string Umi);

Note that this class does not have a package name, then you want to javah generate. h file, the direct shell or command prompt to the Java class in the directory, with Javac Hello.java into class files, You can see a hello.class file, then you can javah hello to generate. h files. The generated. h file is in the current directory, which is the directory where the class file resides.


If this class has a package name, such as:

Com.company.helloworldproject.Class
public class hello{public
    static native string init (string Umi);
Well, the complete directory of this class is almost here: D:\my\app\src\main\java\com\company\helloworldproject\Class, (Take this directory for example) when the shell or command prompt comes to your project's folder Java directory, run the Javah package name. Class name is Javah Com.company.helloworlproject.class.hello can directly generate the. h file, do not need to javac into class file.

Summary: Javah generation. h file, if your Java class is a package name, should not go to the directory where the class files run the Javah command, but should be in the package name of the previous directory run, that is, run: Javah Package name + class name. class, generated. h files in the Java directory.

If the Java class is not a package name, Javah runs directly in the directory where the shell is located in the class file: Javah class name. class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.