Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 58
  1. #21
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    yes the applet runs on the client, but the code and the image folder is at the server, right!
    So what do I do to access the folder through the server and display the images at the client's
    That is my question Tolls.

  2. #22
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    No.
    The code goes to the client, which is how the applet runs.
    Applets run ont he client, which means the code is copied to the client to run.

    If you want the applet to access the images then you need to provide access to them via, presumably, http...so an Apache server?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #23
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    wow that's getting complicated. I should do a path from the applet downloading client
    towards the server that contains the image folder?

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    No, you need to learn how http works, and how to set that up.
    You might be able to use some other connection (ftp?), but I suspect that's not allowed on unsigned applets.

    Since your applet will end up residing on a web server anyway then sticking your images in an associated location shouldn't be a problem.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Though I am pretty confused now, Tolls. Because some four years ago I did write a small
    image showing applet which worked pretty much according the same principle (see small code
    snippet) Did the server grant some sort of permission to load the images from folder?
    I do not remember that detail.
    This Applet really worked for several years on many client computers that saw my small
    non commercial website.



    Java Code:
    private Image downloadImage(String filename) {     			// two file readers            
             Image images=null;
    	URL url;
                url = getClass().getResource("Imagestore/" + filename);
            try {
                images = ImageIO.read(url);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(infoPane, "can not read file " + ex);
            }
                try {
                imgwidth = images.getWidth(this);
                }
                catch (Exception e) {
                    JOptionPane.showMessageDialog(infoPane, "can not get image width " + e);
                }
                try {
                imgheight = images.getHeight(this);
                }
                catch (Exception e) {
                    JOptionPane.showMessageDialog(infoPane, "can not get image height " + e);
                }
                x = (int)(framew - imgwidth)/2;
                y = (int)(frameh - imgheight)/2;
                
        return images;
        }

  6. #26
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    What you mean by this "your images in an associated location"
    1) have it put into the jar file
    2) at the Dir of the applet on the server into a e.g. image folder

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    Java Code:
    getClass().getResource("Imagestore/" + filename);
    That's loading it from either the jar file the class was contained in, or the Imagestore folder on the server (ie where the applet code resides).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #28
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Right (the Imagestore folder on the server where the applet code resides),
    that was working before but is not working now, why?

  9. #29
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Let me try to understand it right:
    1) the applet code plus the images folder is at the server
    2) when a client enters the webpage the applet gets loaded
    to perform
    3) the image files are downloaded from the server

    so it is the server that should grant permission?
    If so how do you do that?

  10. #30
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    This does not really help to get along these security issues
    Finding and Loading Data Files (The Java Tutorials > Deployment > Java Applets)

  11. #31
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    What is going on here please help I do not understand this!
    (the tag and applet class are at the same dir. of course)
    I wrote a simple hello world applet named simpleapplet.class
    The applet tag is:

    Java Code:
    <HTML>
    <Head>
    <Title> A Simple Program </Title>
    <Body>
    
    <applet code="simpleapplet.class" width="350" height="390"></applet>
    
    </Body>
    </HTML>
    and I am still getting this message:

    java.lang.NoClassDefFoundError: simpleapplet (wrong name: slideshow/simpleapplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :615)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:141)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Ap plet2ClassLoader.java:257)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(P lugin2ClassLoader.java:263)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Pl ugin2ClassLoader.java:193)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Pl ugin2ClassLoader.java:174)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plu gin2ClassLoader.java:703)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Plu gin2Manager.java:3052)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1497)
    at java.lang.Thread.run(Thread.java:680)

  12. #32
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    the same old story: java.lang.ClassNotFoundException-screenshot-java-classes.png

    This problem is really weird.
    The above screenshot shows the two groups of class files
    Both applets work on the Netbean apple viewer!
    When I set the tag for "Imgslides" the applet works
    But when I set the tag for "SlideShowApplet" the
    browser shows the class not found error:

    java.lang.NoClassDefFoundError: SlideShowApplet (wrong name: slideshow/SlideShowApplet)

    does that make any sense?





    Java Code:
    <HTML>
    <Head>
    <Title> A Simple Program </Title>
    <Body>
    
    <applet code="SlideShowApplet" width="350" height="390"></applet>
    
    </Body>
    </HTML>
        </body>
    </html>

  13. #33
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    Your class is in a package called 'slideshow', so should be referenced as such.
    I can't remember whether it is a '.' separator (slideshow.SlideShowApplet) or a '/' (slideshow/SlideShowApplet) in the applet tag, and the class file needs to be in the correct folder.
    It works in Netbeans because you haven't mucked up the packaging.

    As for the images, the reason getClass.getResource worked is because it knows to go back to the server if it's not available in any referenced jar and look based on the path. A bit like the <img> tag in html. Your other code is using File, which, as I said several times, uses the local file system.

    Applet security is handled by the browser plug in, so is client side. It's the client that prevents things like file system access on the client, or allowing an applet to access a site it did not come from.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #34
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    So where to begin solving this applet mess?
    Here is a quote from the Core Java (first volume) book that says that there is a difference between the client comp and the server!
    So you can get files from the server but not from the client:

    The images and audio clips must be located on the same server that hosts the applet code. For security reasons, applets cannot access files on another server (“applets can only phone home”).

    You can retrieve images and audio files [from the server] with the getImage and getAudioClip methods. For example:
    Image cat = getImage(getDocumentBase(), "images/cat.gif"); AudioClip meow = getAudioClip(getDocumentBase(),
    "audio/meow.au");
    Here, we use the getDocumentBase method that returns the URL from which your applet is loaded. The second argument to the URL constructor specifies where the image or audio clip is located, relative to the base document. (Applets do not need to go through a Toolkit object to get an image.)

  15. #35
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Tolls can we please go over this stuff from the beginning.
    (because it is so confusing that I do not know where to start)

    I have a real simple Hello word Applet called "simpleapplet.class"
    next see the HTML Tag (both at the same Dir.)

    AND I CANNOT EVEN GET THIS TO WORK, SO WHAT IS GOING WRONG HERE?

    get an java.lang.NoClassDefFoundError: simpleapplet (wrong name: slideshow/simpleapplet)


    Java Code:
    <HTML>
    <Head>
    <Title> A Simple Program </Title>
    <Body>
    
    <applet  code="simpleapplet.class" width="350" height="390"></applet>
    
    </Body>
    </HTML>
    </body>
    </html>

  16. #36
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    BTW I also tried:
    <applet code="slideshow.simpleapplet.class" width="350" height="390"></applet>
    still the same error!
    (it should be a dot separator)

    Here is the simple applet code

    Java Code:
    import javax.swing.JApplet;
    
    
    
    public class simpleapplet extends JApplet
    {
       public void paint(java.awt.Graphics g)
       {
            g.drawString("Hello World!",50,25);
            System.out.println("Hello World!");
        }
    }

    This code is similar to my slideshow applet:

    Loading Images
    Last edited by willemjav; 04-17-2013 at 07:43 PM.

  17. #37
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Where can I find this and how to set it:

    Notes:

    The URL can be any regular URL or simply the name of a policy file in the current directory, as in
    java -Djava.security.manager -Djava.security.policy=mypolicy WriteFile
    The "-Djava.security.manager" argument ensures that the default security manager is installed, and thus the application is subject to policy checks. It is not required if the application SomeApp installs a security manager.

  18. #38
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    what is this about
    grant {
    permission java.security.AllPermission;
    };

  19. #39
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    You're going to need to go through the tutorials.
    We can't possibly act as a substitute here.
    Applets tutorial.
    Deploying an applet.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  20. #40
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Ok Tolls, I am close to a solution.
    The permission are granted by a small file called applet.policy generated by Netbeans
    So when running the appletviewer from Netbeans the file grants permission and
    is situated right in the package folder, the content BTW is:
    grant {
    permission java.security.AllPermission;
    };

    So my question is once you have the classes compiled and copied into a folder
    called classes and you have a applet tag like this:
    <APPLET codebase="classes" code="slideshowapplet/SlideShowApplet.class" width=350 height=200></APPLET>
    where the folder slideshowapplet holds the folder "classes" which contains the principle class:
    SlideShowApplet.class, right!
    WHERE WOULD THIS "applet.policy" GO IN ORDER TO WORK CORRECTLY AND GRANT THE PERMISSION?

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. java.lang.ClassNotFoundException
    By oim415 in forum New To Java
    Replies: 3
    Last Post: 11-19-2012, 11:01 AM
  2. java.lang.ClassNotFoundException - Issue
    By C.phantasy in forum New To Java
    Replies: 3
    Last Post: 11-05-2012, 04:58 AM
  3. java.lang.ClassNotFoundException
    By djgovins in forum Java Servlet
    Replies: 4
    Last Post: 07-25-2011, 11:54 AM
  4. Replies: 8
    Last Post: 11-04-2010, 01:46 PM
  5. java.lang.ClassNotFoundException
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-07-2008, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •