Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Java Applet not running

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Applet not running

    Hello, everyone:

    I'm trying to develop a Java Applet using Eclipse. I'm loading images and text files just fine, but only when I run it through Eclipse. The problem is when I try to run it from the .html file, the window tells that there are Errors, but the detail window doesn't show absolutely anything, just this (and other times (with different projects) I've tried it actually shows exception):

    Java Plug-in 10.3.1.255
    Using JRE version 1.7.0_03-b05 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Jose
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------


    This is the .html code:

    <HTML>
    <HEAD>
    	<TITLE>Quien Quiere ser Millonario</TITLE>
    </HEAD>
    <BODY>
    	<APPLET ID="My Applet" Archive="prueba.jar" CODE="QQSM.class" codebase="/prueba_applet/AA.txt/" WIDTH=800 HEIGHT=800>
    	</APPLET>
    </BODY>
    </HTML>

    Has anyone had this problem before or have any ideas on how to solve it? It's nagged me for about 3 days now =/

    Thanks in advance
    Last edited by jdcb92; May 15th, 2012 at 07:52 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,684
    Thanks
    25
    Thanked 333 Times in 309 Posts

    Default Re: Java Applet not running

    Can't really help you without any indication of what is happening. Put in some print statements or something and open the java console while the program runs so we know what happens. Is it even loading the applet or does it load correctly and you have a runtime crash? Are you using any external libraries?

    Eclipse has something called an Applet Viewer. It is good for debugging, but does not guarantee the program will work in a browser as expected by any means.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Applet not running

    Thank you for your quick reply.

    The Applet just doesn't run at all. It just throws there is error, but then no details are shown.

    I'm importing these libraries:

    import Arboles.*;
    import Lista.*;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Random;

    The first 2 are 2 packages I've made which are in the .jar file.

    Also, I wasn't able to find that Applet Viewer you mentioned. Any hint on where I can find that option?

    Thanks in advance

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,684
    Thanks
    25
    Thanked 333 Times in 309 Posts

    Default Re: Java Applet not running

    The Applet Viewer is what Eclipse uses to run Applets inside the IDE. You mentioned it working in Eclipse, but not in the html page.

    How are you reading the text and image files?

    If the applet runs in Eclipse's Applet Viewer, there are no permission issues with the way you are accessing the text and image files, and it is still failing at running, it leads me to believe your error is in your html code. I've seen the codebase attribute cause considerable problems for people, is it essential for your program? If not, try removing it and see if that helps.
    What about the QQSM class? Does it extend Applet, JApplet, or anything like that?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Applet not running

    Well, I removed the codebase attribute and the same thing happened. An Error with no details. Also, I've put several print to the code, but still, nothing appears.

    This is the code for the text and images (in spanish, tho):

    public class QQSM extends JApplet implements ActionListener
    {
            //Attributes
    	arbolRojiNegro pregs;
    	AATree<Integer> probs;
    	AVLTree opciones;
    	Binario scores;
    	SplayTree correcta;
    	int contCorrectas = 0;
    	int puntaje = 0;
    	nodoRojiNegro nodoPreg;
    	int nPregunta;
    	ListaSimple listaMalas;
     
    	JButton acceso,salir,puntajes,retroceder1,retroceder2;
    	JButton opcion1,opcion2,opcion3,opcion4;
    	JButton comodin1,comodin2,comodin3;
    	ImageIcon imagen1,imagen2;
    	JTextArea expresion,recorrido;
    	JLabel pregunta,labelI,anuncio,labelPuntuacion,label1,label2,label3,label4,label5;
    	JPanel Panel;
     
    //MÉTODOS DEFAULT APPLET
    	public void init()
    	{
    		//Text File Inicialization
    		System.out.println("Inicia Lectura");
    		Archivos archAA = new Archivos("AA.txt");
    		probs = archAA.probabilidades();    //Returns a tree, for functional purposes
    		Archivos archRyN = new Archivos("RyN.txt", expresion, recorrido); //(This is different for GUI reasons)
    		pregs = archRyN.preguntas();
    		Archivos archAVL = new Archivos("AVL.txt");
    		opciones = archAVL.opciones();
    		Archivos archBin = new Archivos("Binario.txt");
    		scores = archBin.puntajes();
    		Archivos archSplay = new Archivos("Splay.txt");
    		correcta = archSplay.respuestas();
    		System.out.println("Termina Lectura");
    		archAA.close();
    		archRyN.close();
    		archAVL.close();
    		archBin.close();
    		archSplay.close();
    	}
     
    Archivos(String direccion) //Archivos (Text File) Constructor
    	{
    		try
    		{
    		archivo = new File(direccion);
    		lector = new FileReader(archivo);
    		bufferLectura = new BufferedReader(new FileReader(archivo));
    		System.out.println("Se abrió el archivo "+direccion+" correctamente");
    		}
    		catch(Exception Ex){System.out.println("No se encontró el archivo"+direccion);Ex.printStackTrace();}
    	}
     
    The image portions:
     
    		labelI = new JLabel();
    		labelI.setIcon(new ImageIcon(getClass().getResource("imagen1.jpg")));
    		labelI.setSize(900, 530);
    		labelI.setLocation(0, 0);
     
    		labelII = new JLabel();
    		labelII.setIcon(new ImageIcon(getClass().getResource("imagen2.jpg")));
    		labelII.setSize(600, 250);
    		labelII.setLocation(0, 0);

    All images and text files are included in the .jar compilation.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,332
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java Applet not running

    An Error with no details.
    Perhaps I missed it in the above posts, but what error? Post it in its entirety.

    This thread has been cross posted here:

    http://www.java-forums.org/java-applets/59782-java-applet-not-running.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  7. #7
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Applet not running

    Ok. I'm really sorry about the Cross Posting rules, I wasn't aware of it and will take into account in the future.

    The thing of the Error with no details is that when I run the applet, the applet says "Error. Click for details", but when I click I just get this:


    Java Plug-in 10.3.1.255
    Using JRE version 1.7.0_03-b05 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Jose
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------

    Generally, the exception stack trace would appear after the "------------------------------", but this is not the case and therefore I don't know what the error might be. And I've looked everywhere, but wasn't able to find a problem like this one.

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,332
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java Applet not running

    It is difficult to determine what's going on without a defined exception stack trace. My advice - break the applet down. Either start from scratch and make sure a simple Applet will work then build up from there, or break down what you have until it does work then build up to determine the problem.

    The imports you list are not common, and although you don't import anything from java.io (based upon what you posted, which isn't much), I do notice File and FileReader (this a very good reason to NOT import entire libraries, but each class at a time - it eliminates ambiguity)...which if from the java.io package, I recommend reading What Applets Can and Cannot Do (The Java™ Tutorials > Deployment > Java Applets)

  9. #9
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,684
    Thanks
    25
    Thanked 333 Times in 309 Posts

    Default Re: Java Applet not running

    You might find you have a slight problem with your reading down the road, although it would not explain your current problem. Basically, if you plan on deploying this on a web server, and you plan on having the text and image files on the server as well, you need to use InputStreams instead of normal files. Like I said however, this problem would not lead to your applet not even loading properly (you would get runtime exceptions thrown when it tries to read the text files and images, but the applet itself would still load).

    Is your jar file in the same location as your html file?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  10. #10
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Applet not running

    Thanks everyone for your replies. I've finally solved the problem and it was a combination of several things:

    The first one is that I was using internal packages, and for some reason it just didn't work that way so I just used the default package and it worked fine, but it gave the permission to read text files errors, which appeared weird to me because the .jar was already signed. After that, I just didn't complicate myself and sent the text files through parameters and voilá...it worked. Hope this works for someone in the future.

    Thanks to everyone who contributed.

Similar Threads

  1. MySQL Quit while java application is running
    By aueddonline in forum JDBC & Databases
    Replies: 6
    Last Post: February 6th, 2012, 01:55 PM
  2. Error Running Java in Eclipse
    By steadyonabix in forum Java IDEs
    Replies: 1
    Last Post: September 3rd, 2011, 10:28 PM
  3. Error while running Applet
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 1st, 2011, 04:02 AM
  4. Running an Applet With JAR file
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 20th, 2011, 07:10 AM
  5. Running servlet from java project
    By raj07 in forum Java Servlet
    Replies: 1
    Last Post: February 19th, 2011, 06:11 PM