• Post Reply Bookmark Topic Watch Topic
  • New Topic

A JNI error occurred  RSS feed

 
Jack kelly
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know what I'm doing wrong but every time I try to run this it says "Error: A JNI error occurred, please check your installation and try again"



Please help.

[edit]Add code tags blank lines and indentation. Leave incorrect package name unchanged. CR[/edit]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack,
Welcome to CodeRanch! is that the full error message?

First thing is to change your package name. "java" is meant for code that Oracle is providing to you as Java itself. For your first program, just remove the package statement entirely. This puts you in the default package and lets you run without thinking about directory structure.

If it still doesn't work, show the command you used to compile and run.
 
Jack kelly
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Removed package but it still wont work and I use eclipse
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote: . . . is that the full error message?
. . . .
No it isn't. This might be more like it
campbell@campbell-ChromebookC720:~$ javac java/Scanning.java
campbell@campbell-ChromebookC720:~$ java java.Scanning
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Prohibited package name: java
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:659)
at java.lang.ClassLoader.defineClass(ClassLoader.java:758)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
campbell@campbell-ChromebookC720:~$
Try again minus the prohibited package name, which Jeanne picked up, and you should find it works.

And welcome again. I shall add code tags to your post and add the missing indentation as per our suggestions, and it will look a lot better
What does bucky mean? It doesn't look a good name for a Scanner for input.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to recompile your code. Most of us here think it is a bad idea to start using IDEs (e.g. Eclipse) while you are still beginning Java®.
 
Jack kelly
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much it was the package I hadn't actually fully removed it .

 
Jack kelly
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should I be using instead of an IDE
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notepad or the text editor of your choice.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not Notepad.

There are editors and there are editors and there is Notepad. We have an FAQ about editors.

If you insist on using Eclipse you will have to change the name of the package. As you see the javac tool compiled your class but the java tool wouldn't execute it because of the package name.
Look at our First Program FAQ. You will presumably already have set your PATH and installed Java® otherwise you wouldn't get that error message. The rest of the FAQ tells you what to do instead of using Eclipse.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Jack kelly
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.Scanner;
public class Scanning {
public static void main(String args[]){
Scanner bucky = new Scanner(System.in);
System.out.println(bucky.nextLine());
}
}

Oh and not sure what you mean by "show the command you use to compile and run" Eclipse I think
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't open a new thread for the same problem. I shall see if I can't merge the two.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming they was meant to be a reply to your other post? Please be sure to use the "Post Reply" rather than "New topic" button when replying.

[Edit: beat to the punch again ;) ]
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The merge didn't seem to work.

[edit]I have found out what I did wrong and the merge has now worked.[/edit]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!