A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
public class LoginCumReg implements ActionListener,KeyListener { private JFrame form; private JTextField txtunm; private JTextField txtnm; private JTextField txteml; private JButton cmdcreate; private JPasswordField txtpass; private JPasswordField txtpassreg; private JButton cmdok; private JLabel lblunm; private JLabel lblpass; private JLabel lbleml; private JLabel lblpassreg; private JLabel lblnm; private JPanel panel_1; public LoginCumReg() { // construct components form = new JFrame("Sign Up"); form.getContentPane().setFont( new Font("Plantagenet Cherokee", Font.BOLD, 18)); txtunm = new JTextField(5); txtunm.addKeyListener(this); txtunm.setBounds(637, 55, 100, 25); txtnm = new JTextField(5); txtnm.setBounds(637, 228, 100, 25); txteml = new JTextField(5); txteml.setBounds(637, 264, 100, 25); cmdcreate = new JButton("Create Account"); cmdcreate.setBounds(527, 350, 188, 25); txtpass = new JPasswordField(5); txtpass.setBounds(637, 91, 100, 25); txtpassreg = new JPasswordField(5); txtpassreg.setBounds(637, 300, 100, 25); cmdok = new JButton("OK"); cmdok.setBounds(527, 139, 100, 25); lblunm = new JLabel("UserName"); lblunm.setBounds(527, 55, 73, 25); lblpass = new JLabel("Password"); lblpass.setBounds(527, 91, 100, 25); lbleml = new JLabel("Email ID"); lbleml.setBounds(527, 264, 100, 25); lblpassreg = new JLabel("Password"); lblpassreg.setBounds(527, 300, 100, 25); lblnm = new JLabel("Full Name"); lblnm.setBounds(527, 228, 100, 25); // form.setResizable(false); // adjust size and set layout form.setPreferredSize(new Dimension(800, 450)); form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); form.getContentPane().setLayout(null); // add components form.getContentPane().add(txtunm); form.getContentPane().add(txtnm); form.getContentPane().add(txteml); form.getContentPane().add(cmdcreate); form.getContentPane().add(txtpass); form.getContentPane().add(txtpassreg); form.getContentPane().add(cmdok); form.getContentPane().add(lblunm); form.getContentPane().add(lblpass); form.getContentPane().add(lbleml); form.getContentPane().add(lblpassreg); form.getContentPane().add(lblnm); cmdcreate.setActionCommand("Create Account"); cmdcreate.addActionListener(this); cmdok.setActionCommand("Login"); JPanel panel = new JPanel(); panel.setBounds(502, 29, 254, 154); panel.setFont(new Font("Palatino Linotype", Font.PLAIN, 14)); panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.RAISED, null, null), "LOGIN", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel.setBackground(SystemColor.controlHighlight); form.getContentPane().add(panel); panel_1 = new JPanel(); panel_1.setBounds(500, 204, 254, 186); panel_1.setFont(new Font("Palatino Linotype", Font.PLAIN, 14)); panel_1.setBorder(new TitledBorder(new EtchedBorder( EtchedBorder.RAISED, null, null), "SIGN UP", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel_1.setBackground(SystemColor.controlHighlight); form.getContentPane().add(panel_1); JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setBounds(91, 139, 286, 101); lblNewLabel.setIcon(new ImageIcon( "C:\\Users\\JAsh\\Desktop\\Projects\\JAsh.png")); form.getContentPane().add(lblNewLabel); JPanel panel_2 = new JPanel(); panel_2.setBounds(77, 118, 315, 145); panel_2.setBorder(new EtchedBorder(EtchedBorder.RAISED, SystemColor.activeCaptionBorder, SystemColor.menu)); panel_2.setBackground(SystemColor.controlHighlight); form.getContentPane().add(panel_2); cmdok.addActionListener(this); form.setResizable(false); form.pack(); form.setVisible(true); System.out.println("const.."); } public static void main(String[] args) { new LoginCumReg(); } @Override public void actionPerformed(ActionEvent ae) { // TODO Auto-generated method stub if (ae.getActionCommand().equals("Create Account")) { new Registration(txtnm.getText(), txteml.getText(), new String( txtpassreg.getPassword())); form.setVisible(false); } if (ae.getActionCommand().equals("Login")) { try { if (txtunm.getText().equalsIgnoreCase("admin") && new String(txtpass.getPassword()).equals("admin")) { form.setVisible(false); new Admin(); } else { DataBase db = new DataBase(); db.connect(); String sql = "SELECT * FROM LOGIN WHERE USERNAME='" + txtunm.getText() + "'"; ResultSet rs = db.getDDL(sql); boolean found = false; while (rs.next()) { if (rs.getString("Password").equals( new String(txtpass.getPassword()))) { found = true; form.setVisible(false); String name = rs.getString("FullName"); Session.startSession(txtunm.getText(), name); new FacultyWelcome(); } } if (!found) JOptionPane.showMessageDialog(new JFrame(), "Invalid Credentials"); db.close(); } } catch (Exception e) { } } } @Override public void keyPressed(KeyEvent arg0) { // TODO Auto-generated method stub } @Override public void keyReleased(KeyEvent arg0) { // TODO Auto-generated method stub } @Override public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub // JOptionPane.showMessageDialog(new JFrame(), arg0.getKeyChar()+"-"+arg0.getKeyCode()); }
}
The above code works perfectly on my friend's laptop and throws this error on my laptop. I have running the code on Eclipse Juno using Java 7. I have also tested and run a lot java programs on my laptop all works well. This is the only program which gives such an error. This is my final year project and I need it to work on my laptop, I will be greatful to anyone who helps
回答1:
Short answer: Right click on the class that contains the main method. Click on "Run As". Click on "Java Application". The keyboard shortcut is: Shift+Alt+X J (while holding Shift and Alt, press X; then release Shift and Alt and press J).
Long answer: To be honest, I am not 100% sure why this problem happens. It might be because of using a different jdk. I faced the same error. The solution was easier than what I imagined. I was used to running my code using Ctrl + F11. But when I ran it as a java application (the way I described in "short answer"), the problem was resolved. I am not sure if it solves other peoples' problems as well, but it is worthwhile to try. :)
回答2:
I had similar issues when using 'java' at the beginning of the package name, e.g. java.jem.pc
Check your console output, I was receiving: Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.jem.pc
回答3:
I also faced the same issue. By looking at the console that's saying
java.lang.SecurityException issue.
the Solution is:
Check your package name of your project.
Hope your issue will be resolved. If not, then please print your console trace for tracking the root cause.
回答4:
Error: A JNI error has occurred, please check your installation and try again in Eclipse
Solution: Check your package name as it may be colliding with the package name in java. Simply change the package name to resolve your issue. :)
回答5:
In my case the issue was caused by the JDK version. To solve this I suggest to go into your pom file and check the 1.7.
Afterwards check java version in your cmd(windows) or terminal ( OSX or LINUX ) by typing : java -version.
Compare the version shown in the terminal\command prompt with what you have in your pom file. Make sure they are the same. Then run your project again.
回答6:
You can check the console first to see the actual error message then proceed by looking for answers for that error.
My console shows the error NoClassDefFound for the class jcommander. Your error will probably be different from mine. The cause of my error is that the class jcommander is not in my M2 repository, so I just have to add that dependency in my pom.xml. You can check if all the class dependencies are all declared and added in your current config and project build.
Check your console. It says java.lang.SecurityException issue. Change your 'package name'. I changed my package name from 'java.assessment' to 'assesment' and it worked for me. If somebody knows the root cause , let me know please.
回答9:
I faced a similar problem and than got the solution in the package name. I kept the package name as java.basics. In the console I got a hint for that as it clearly said Prohibited package name. So I changed package name and it worked.
回答10:
edit the ".classpath" and include below tag
this could solve your problem.
回答11:
I hope this helps somebody else. I was suffering with this while working on a project a few years ago and then a job in a newer project started failing a few days ago. I found this post and was trying to recollect what I had modified in my project and then I remembered that I had changed my maven pom and removed the entry for maven-jar-plugin. When you build a jar whose purpose is to be executable, you need to include this so that certain entries get written into the manifest. I opened the old project, copied that entry (with some modifications for project name) and it worked.
回答12:
I think this happen because the name of your class is the same name of another class in the JDK . Help eclipse to determine which one you are trying to run by selecting the package your class is in . Go to run configuration select the project and the main class.
When you press the search button to select the main class, you will find options that have the same name but different package, select your class.
回答13:
POSSIBLE SOLUTION If NONE of these solutions worked for you then try this... I finally got mine working by deleting the two folders ".metadata" & ".recommenders" in the workspace folder. You can find your workspace folder path by clicking on "File">"Switch Workspace">"Other" in the Eclipse application's toolbar.
Now I am a complete noob crying my way through an SE degree at San Jose State University. So I am just sharing what worked for me without knowing much knowledge of why exactly. I do not know what harm or headaches, or even if both aforementioned folders needed to be deleted. But in the end, it worked for me and it seems the application just recreates fresh versions of those folders anyways.
回答14:
My issue came from trying to disable the Maven nature from my project and then deleting the pom.xml file. This is bad, very bad, don't do this. If you do, change it back to a Maven project and hopefully you can either restore your old pom.xml file or create a new one. As soon as I did that, it worked again.
回答15:
There was no information in my Console so that sent me searching for additional solutions and found these - unique to the solutions presented here. I encountered this with Eclipse Oxygen trying to run an old Ant build on a project.
Cause 1 I had configured Eclipse to use an external Ant install which was version 1.10.2 which apparently had classes in it that were compiled with JDK 9. In Eclipse I got the JNI error described above (running the Ant build at the command line gave me the reknowned 'unsupported major.minor version' error - the Java I was using on the system was JDK 8).
The solution was to rollback to the embedded Eclipse version of Ant being 1.10.1. I verified this as the correct solution by downloading Ant 1.10.1 separately and reconfiguring Eclipse to use the new 1.10.1 externally and it still worked.
Cause 2 This can also happen when you have the Ant Runtime settings configured incorrectly in Eclipse's Preferences. Depending on the version of Ant you're running you will need to add the tools.jar from the appropriate JDK to the classpath used for the Ant Runtime (Home Entries). More specifically, without a proper configuration, Eclipse will complain when launching an Ant target that the JRE version is less than a particular required version.
Essentially, 'proper configuration' means aligning each of the configuration items in Eclipse for running Ant so that they all work together. This involves the Ant Runtime Home entry (must point to an Ant version that is compatible with your chosen JDK -- you can't run Ant with JDK 8 when it was compiled against JDK 9); specifying the tools.jar that belongs to the JDK you want to run Ant with in the Ant Runtime settings; and lastly setting the JRE environment of your build script to the JDK you want to run Ant with in the External Tools Configuration. All 3 of these settings need to agree to avoid the error described above. You'll also need to consider the attributes used in your javac tag to ensure the JDK you're using is capable of executing as you've directed (i.e. JDK 7 can't compile code using source and target version 8).
Moreover If you're really just trying to run an Ant build script to compile code to an older JDK (e.g. less than 8 for Oxygen), this article helped gain access to run Ant against an older JDK. There are Ant plugin replacements for a handful of versions of Eclipse, the instructions are brief and getting the correct plugin version for your particular Eclipse is important.
Or more simply you can use this very good solution to do your legacy compile which doesn't require replacing your Eclipse plugin but instead changing the javac tag in your build script (while using the latest JDK).
回答16:
I have been running into the same error when I add the following maven dependency in my project:
aws-encryption-sdk-java
The error came up only when I ran the shade jar file produced by maven-shade-plugin. I was able to overcome the error by using the jar produced by maven-assembly-plugin.