Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » errors code while running java on windows after installed(Eclipse first use)
errors code while running java on windows after installed [message #1791086] Fri, 22 June 2018 16:16 Go to next message
Phuong Tran is currently offline Phuong TranFriend
Messages: 10
Registered: June 2018
Junior Member
Hi, Please help me to get this error fixed. I have a lenovo 2014 laptop, I 've just downloaded the JSE version 8. Then, I downloaded eclipse.

After I inputted some codes and ran, I received errors( please refer to attachments for error message).
  • Attachment: 1.png
    (Size: 163.29KB, Downloaded 11 times)
  • Attachment: 2.jpg
    (Size: 216.28KB, Downloaded 14 times)
Re: errors code while running java on windows after installed [message #1791087 is a reply to message #1791086] Fri, 22 June 2018 16:25 Go to previous messageGo to next message
Phuong Tran is currently offline Phuong TranFriend
Messages: 10
Registered: June 2018
Junior Member
These are the completed error code message:

Exception in thread "main" java.lang.SecurityException: Prohibited package name: java
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Re: errors code while running java on windows after installed [message #1791099 is a reply to message #1791087] Fri, 22 June 2018 19:42 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 390
Registered: August 2014
Senior Member
Did you read the error message? The cause in on the first line.

Exception in thread "main" java.lang.SecurityException: Prohibited package name: java

Do not attempt to put your code in the package 'java'.


--

Tauno Voipio
Re: errors code while running java on windows after installed [message #1791118 is a reply to message #1791099] Sun, 24 June 2018 00:42 Go to previous messageGo to next message
Phuong Tran is currently offline Phuong TranFriend
Messages: 10
Registered: June 2018
Junior Member
i delete the first row but still same error message, it won't launch.
Here is the code after delete the first row:
public class retail {

public static void main(String[] args) {
int itema=200, itemb=75, itemc=500;
double price;

price=((itema*2)+(itemb)+ (itemc*3));
price=price-(.1*price);
price=price+(.05*price);
System.out.println(price);

}

}


Here is the error message:
xception in thread "main" java.lang.SecurityException: Prohibited package name: java
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)


It 's not about the code , it is errors within the package.
Re: errors code while running java on windows after installed [message #1791119 is a reply to message #1791118] Sun, 24 June 2018 05:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29456
Registered: July 2009
Senior Member
I imagine/guess if you delete the package declaration from the file itself that the file remains in the same location "/java/src/java/retail.java" but in general the package declaration's name must match the Java file's folder path relative to the source root, i.e., "/java/src" is a Java source folder and "java/retail.java" is the relative path of the Java source file. A Java file at that location must have package declaration with the name "java".

I'd suggest you delete everything under your "/java/src" folder (but not the src folder itself) and then use the context menu on the src folder to create a new class by invoking New -> Class from the context menu. In the wizard you can choose the package name (or leave it blank, which is usually not so useful except for toy examples which is why the wizard will tell you this is discouraged) and you can choose the class name (which generally should be a name that starts with an upper case letter, which the wizard will also indicate with a warning that "retail" is not a great style choice according to Java's naming conventions).
Re: errors code while running java on windows after installed [message #1791205 is a reply to message #1791119] Tue, 26 June 2018 01:41 Go to previous messageGo to next message
Phuong Tran is currently offline Phuong TranFriend
Messages: 10
Registered: June 2018
Junior Member
I have a question, I am not sure if my Lenovo has JDE, I assumed every window has a java built in (im not good at PCs stuff). I did google but still not quite get it. I then before download eclipse, I download JDE package 32 bits, then I download eclipse 64bit. I am not sure the eclipse error message is due to any error from the installation?
Re: errors code while running java on windows after installed [message #1791207 is a reply to message #1791205] Tue, 26 June 2018 02:48 Go to previous messageGo to next message
Phuong Tran is currently offline Phuong TranFriend
Messages: 10
Registered: June 2018
Junior Member
I also followed your suggest, delete everything under java/src but not the src itself. Then, right click on src, create new-->class (when I tried to enter the "name", a message located on top of screen stating: the use of the default package is discouraged). I still created anw disregard the message, with the same code as above:

public class retail {

public static void main(String[] args) {
int itema=200, itemb=75, itemc=500;
double price;

price=((itema*2)+(itemb)+ (itemc*3));
price=price-(.1*price);
price=price+(.05*price);
System.out.println(price);

}

}

It did not give me error message like above, but it showed nothing after I hit run. I would be able to create HelloWorld1.java file and it outputs "Hello world". But it does not run for the above example (retail shop, as a class). Please advise
Re: errors code while running java on windows after installed [message #1791211 is a reply to message #1791207] Tue, 26 June 2018 04:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29456
Registered: July 2009
Senior Member
I would expect the Console view to display the contents. By default this view will come to the foreground then new contents are displayed. You can type "Console" in the "Quick Access" entry field near the upper right of the perspective to ensure that view is active. Perhaps it's related to using a lower case name for the class name, which I've already suggested is bad Java style... Try to set a breakpoint in your code and debug it to see that indeed it's running.
Re: errors code while running java on windows after installed [message #1791215 is a reply to message #1791207] Tue, 26 June 2018 05:48 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3202
Registered: July 2009
Senior Member

Don't disregard the contents of the message. Put your class in a package, one not named "java", and try again.

Nitin Dahyabhai
Eclipse Web Tools Platform
Re: errors code while running java on windows after installed [message #1791241 is a reply to message #1791215] Tue, 26 June 2018 15:09 Go to previous messageGo to next message
Phuong Tran is currently offline Phuong TranFriend
Messages: 10
Registered: June 2018
Junior Member
I did not input: package java.
When I right click src-->NEW-->Class, then: input name, check the box: public static void main string [] args. after that, it popped up a window with these lines already there:

package java;
public class retail {
//todo......

There are all the codes that are already there after I create a new class to work on the codes. I am not coming up these ways myself. I learned JAVA online on Youtube. I followed the instruction like the video said but I dont know how come i get all these of error and the console did not execute but instead giving me all kinds of errors. I am not sure if I made any mistake by installing the wrong JSE package. Is that because I already had 1 built in and I went download another one, so it was duplicate or redundant?
Re: errors code while running java on windows after installed [message #1791242 is a reply to message #1791241] Tue, 26 June 2018 15:31 Go to previous message
Phuong Tran is currently offline Phuong TranFriend
Messages: 10
Registered: June 2018
Junior Member
before I download the JSE package, I did go to control panel--program and features, I saw only 1 java was built in then nothing else, no JDK or JSE. So I assumed I did not have JSE installed and went ahead to install it.
Previous Topic:File location for cheat sheet
Next Topic:Getting Permission Denied exception when using market place
Goto Forum:
  


Current Time: Fri Jul 20 08:48:54 GMT 2018

Powered by FUDForum. Page generated in 0.02924 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top