#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Threads and JVM error


    Hi everybody,

    I was programming basic threads and I haven't encountered any errors but when I try and run the program I encounter the error "A Java exception has occurred". I use two different classes one with the main method and one without to run my thread program.
    I will give you the two classes Below:

    Main Method:

    package java.thenewboston.gamedev;

    public class ThreadBasicsMain
    {

    public static void main(String[] args)
    {

    Thread t1 = new Thread(new ThreadBasics("One"));
    Thread t2 = new Thread(new ThreadBasics("Two"));
    Thread t3 = new Thread(new ThreadBasics("Three"));
    t1.start();
    t2.start();
    t3.start();

    }

    }

    All Of The Meat:

    package java.thenewboston.gamedev;

    import java.util.Random;

    public class ThreadBasics implements Runnable
    {

    String name;
    int time;
    Random r = new Random();

    public ThreadBasics(String s){

    name = s;
    time = r.nextInt(6666);

    }

    public void run()
    {
    try{
    System.out.printf("%s is sleeping for %d\n", name, time);
    Thread.sleep(time);
    System.out.printf("%s is done\n", name);
    }catch(Exception e){}


    }

    }



    Thanks for any help
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1712
    I get no errors running your program:

    Code:
    scott@jalapeno:$ java ThreadBasicsMain
    One is sleeping for 849
    Two is sleeping for 5259
    Three is sleeping for 1871
    One is done
    Three is done
    Two is done
    This was run on the command line and I removed the package statements. Can you elaborate on the error?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by stdunbar
    I get no errors running your program:

    Code:
    scott@jalapeno:$ java ThreadBasicsMain
    One is sleeping for 849
    Two is sleeping for 5259
    Three is sleeping for 1871
    One is done
    Three is done
    Two is done
    This was run on the command line and I removed the package statements. Can you elaborate on the error?
    This is what appears in the console error message:

    Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.thenewboston.gamedev
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:650)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:786)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

    Thanks for responding
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    Are you running this in an applet?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by bullet
    Are you running this in an applet?
    I am running this through the console and it is supposed to be a simple program I don't know why it is doing this. My other projects in eclipse work fine it is just this one that is giving me troubles.
  10. #6
  11. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    I don't think the error is in your code. I believe the problem is that you are not allowed to create a class using a package that begins with the name java.

    This is from the source of java.lang.ClassLoader.

    Code:
    if ((name != null) && name.startsWith("java.")) {
                throw new SecurityException
                    ("Prohibited package name: " +
                     name.substring(0, name.lastIndexOf('.')));

    Comments on this post

    • stdunbar agrees : I should have caught that myself
    • jsav246 agrees : Thanks for Solving my Problem
    Last edited by bullet; August 20th, 2013 at 08:19 AM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by bullet
    I don't think the error is in your code. I believe the problem is that you are not allowed to create a class using a package that begins with the name java.

    This is from the source of java.lang.ClassLoader.

    Code:
    if ((name != null) && name.startsWith("java.")) {
                throw new SecurityException
                    ("Prohibited package name: " +
                     name.substring(0, name.lastIndexOf('.')));
    Alright thanks for the help. I was wondering about that myself but I didn't know that would cause that type of problem.

IMN logo majestic logo threadwatch logo seochat tools logo