Page 5 of 6 FirstFirst ... 3456 LastLast
Results 81 to 100 of 101
  1. #81
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    <<ALL FILES>> doesn't make sense for properties. Try this:
    permission java.util.PropertyPermission "*", "read, write";
    If you don't understand my response, don't ignore it, ask a question.

  2. #82
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    I typed that myself because the policytool said I needed a target and so I just copied the other one.
    So is * the target now?

  3. #83
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    I posted the contents of my policy file. Copy from it.
    If you don't understand my response, don't ignore it, ask a question.

  4. #84
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Progress has been made! Now this happens:

    java.lang.NullPointerException
    at Tetris.HighScores.addToFile(HighScores.java:111)
    at Tetris.HighScores.rewrite(HighScores.java:258)
    at Tetris.HighScores.<init>(HighScores.java:41)
    at Tetris.BlockController.<init>(BlockController.java :27)
    at Tetris.Tetris.init(Tetris.java:20)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    Exception in thread "Thread-12" java.lang.NullPointerException
    at Tetris.Tetris.run(Tetris.java:39)
    at java.lang.Thread.run(Unknown Source)

  5. #85
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    Yes, back to regular problems.
    Look at line 111 and see what variable is null, then backtrack in the code to find out why the variable does not have a valid value.
    If you don't understand my response, don't ignore it, ask a question.

  6. #86
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    The line is:
    writer.write(line);
    So I did system.out.println(line);
    And it printed out 0 so I guess it could mean that it's not working. Since I edited it so it should be all equal to 10.

    Before that, it was called from:
    for(int x = 0; x < 10; x++){
    addToFile(normalHighScores[x]);
    }
    normalHighScores gets initialized here:
    File test = new File("./Blocks/NormalHighScores.txt");
    try {
    scanner = new Scanner(test);
    } catch (FileNotFoundException e){}
    try{
    for(int x = 0; x < 10; x++){//0-10 = greatest - lowest score
    String line = scanner.nextLine();
    if(line == null){
    break;
    }else{
    normalHighScores[x] = line;
    }
    }
    }catch(Exception e){}

  7. #87
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    writer.write(line);
    What about the value of writer?

    This is bad: }catch(Exception e){} and catch (FileNotFoundException e){}
    All catch blocks should have a call to the printStackTrace() method in them.
    If you don't understand my response, don't ignore it, ask a question.

  8. #88
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Ok. I changed those things and made it print out writer.toString and it gave me this error:
    java.io.FileNotFoundException: .\Blocks\NormalHighScores.txt (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at Tetris.HighScores.<init>(HighScores.java:26)
    at Tetris.BlockController.<init>(BlockController.java :27)
    at Tetris.Tetris.init(Tetris.java:20)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at Tetris.HighScores.<init>(HighScores.java:32)
    at Tetris.BlockController.<init>(BlockController.java :27)
    at Tetris.Tetris.init(Tetris.java:20)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at Tetris.HighScores.addToFile(HighScores.java:115)
    at Tetris.HighScores.rewrite(HighScores.java:263)
    at Tetris.HighScores.<init>(HighScores.java:45)
    at Tetris.BlockController.<init>(BlockController.java :27)
    at Tetris.Tetris.init(Tetris.java:20)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    Exception in thread "Thread-12" java.lang.NullPointerException
    at Tetris.Tetris.run(Tetris.java:39)
    at java.lang.Thread.run(Unknown Source)
    Since there are too many errors I decided to show you the whole class.
    Java Code:
    package Tetris;
    
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    
    public class HighScores{
    	private String[] normalHighScores = new String[10], timedHighScores = new String[10], HighScores5 = new String[10], timedHighScores5 = new String[10];
    	private BufferedWriter writer, timedWriter, writer5, timedWriter5;
    	private Scanner scanner, timedScanner, scanner5, timedScanner5;
    	public boolean usingTimer, using5;
    	
    	HighScores(){
    		usingTimer = false;
    		using5 = false;
    		for(int x = 0; x < 10; x++){
    			normalHighScores[x] = 0 + "";
    			timedHighScores[x] = 0 + "";
    			HighScores5[x] = 0 + "";
    			timedHighScores5[x] = 0 + "";
    		}
    
    		System.out.println(System.getProperties().getProperty("user.home"));
    		File test = new File("./Blocks/NormalHighScores.txt");
    		try {
    			scanner = new Scanner(test);
    		} catch (FileNotFoundException e){
    			e.printStackTrace();
    		}	
    		try{
    			for(int x = 0; x < 10; x++){//0-10 = greatest - lowest score
    				String line = scanner.nextLine();
    				if(line == null){      
    					break;  
    				}else{
    					normalHighScores[x] = line;
    				}
    			}
    		}catch(Exception e){
    			e.printStackTrace();
    		}
    		try {
    			writer = new BufferedWriter(new FileWriter("./Blocks/NormalHighScores.txt"));
    		} catch (IOException e) {}
    		rewrite(0);
    		
    		
    		try {
    			timedScanner = new Scanner(new File("./Blocks/TimedHighScores.txt"));
    		} catch (FileNotFoundException e){}
    		try{
    			for(int x = 0; x < 10; x++){//0-10 = greatest - lowest score
    				String line = timedScanner.nextLine();
    				if(line == null){
    					break;
    				}else{
    					timedHighScores[x] = line;
    				}
    			}
    		}catch(Exception e){}
    		try{
    			timedWriter = new BufferedWriter(new FileWriter("./Blocks/TimedHighScores.txt"));
    		} catch (IOException e) {}
    		usingTimer = true;
    		rewrite(0);
    		usingTimer = false;
    		
    		
    		try {
    			scanner5 = new Scanner(new File("./Blocks/HighScores5.txt"));
    		} catch (FileNotFoundException e){}
    		try{
    			for(int x = 0; x < 10; x++){//0-10 = greatest - lowest score
    				String line = scanner5.nextLine();
    				if(line == null){
    					break;
    				}else{
    					HighScores5[x] = line;
    				}
    			}
    		}catch(Exception e){}
    		try{
    			writer5 = new BufferedWriter(new FileWriter("./Blocks/HighScores5.txt"));
    		} catch (IOException e) {}
    		using5 = true;
    		rewrite(0);
    		using5 = false;
    		
    		
    		try {
    			timedScanner5 = new Scanner(new File("./Blocks/Timed5HighScores.txt"));
    		} catch (FileNotFoundException e){}
    		try{
    			for(int x = 0; x < 10; x++){//0-10 = greatest - lowest score
    				String line = timedScanner5.nextLine();
    				if(line == null){
    					break;
    				}else{
    					timedHighScores5[x] = line;
    				}
    			}
    		}catch(Exception e){}
    		try{
    			timedWriter5 = new BufferedWriter(new FileWriter("./Blocks/Timed5HighScores.txt"));
    		} catch (IOException e) {}
    		usingTimer = true;
    		using5 = true;
    		rewrite(0);
    		usingTimer = false;
    		using5 = false;
    	}
    	public void addToFile(String line){
    		if(!usingTimer && !using5){
    			try {
    				System.out.println(writer.toString());
    				writer.write(line);
    				writer.newLine();
    			} catch (IOException e) {}
    		}else if(usingTimer && !using5){
    			try {
    				timedWriter.write(line);
    				timedWriter.newLine();
    			} catch (IOException e) {}
    		}else if(!usingTimer && using5){
    			try {
    				writer5.write(line);
    				writer5.newLine();
    			} catch (IOException e) {}
    		}else{
    			try {
    				timedWriter5.write(line);
    				timedWriter5.newLine();
    			} catch (IOException e) {}
    		}
    	}
    	
    	public void closeFile(){
    		boolean temp1 = usingTimer, temp2 = using5;
    		try {
    			writer = new BufferedWriter(new FileWriter("./Blocks/NormalHighScores.txt"));
    		} catch (IOException e) {}
    		usingTimer = false;
    		using5 = false;
    		for(int x = 0; x < 10; x++){
    			addToFile(normalHighScores[x]);
    		}
    		usingTimer = true;
    		try {
    			writer.close();
    		} catch (IOException e) {}
    		
    		
    		try {
    			timedWriter = new BufferedWriter(new FileWriter("./Blocks/TimedHighScores.txt"));
    		} catch (IOException e) {}
    		usingTimer = true;
    		for(int x = 0; x < 10; x++){
    			addToFile(timedHighScores[x]);
    		}
    		usingTimer = false;
    		try {
    			timedWriter.close();
    		} catch (IOException e) {}
    		
    		
    		try {
    			writer5 = new BufferedWriter(new FileWriter("./Blocks/HighScores5.txt"));
    		} catch (IOException e) {}
    		using5 = true;
    		for(int x = 0; x < 10; x++){
    			addToFile(HighScores5[x]);
    		}
    		using5 = false;
    		try {
    			writer5.close();
    		} catch (IOException e) {}
    		
    		
    		try {
    			timedWriter5 = new BufferedWriter(new FileWriter("./Blocks/Timed5HighScores.txt"));
    		} catch (IOException e) {}
    		usingTimer = true;
    		using5 = true;
    		for(int x = 0; x < 10; x++){
    			addToFile(timedHighScores5[x]);
    		}
    		usingTimer = false;
    		using5 = false;
    		try {
    			timedWriter5.close();
    		} catch (IOException e) {}
    		
    		
    		//Restore values
    		usingTimer = temp1;
    		using5 = temp2;
    	}
    	
    	public void read(){
    		try{
    			for(int x = 0; x < 10; x++){
    				String line = scanner.nextLine();
    				if(line == null){
    					normalHighScores[x] = 0 + "";
    					break;
    				}else{
    					normalHighScores[x] = line;
    				}
    			}
    		}catch(Exception e){}
    		
    		
    		try{
    			for(int x = 0; x < 10; x++){
    				String line = timedScanner.nextLine();
    				if(line == null){
    					timedHighScores[x] = 0 + "";
    					break;
    				}else{
    					timedHighScores[x] = line;
    				}
    			}
    		}catch(Exception e){}
    		
    		try{
    			for(int x = 0; x < 10; x++){
    				String line = scanner5.nextLine();
    				if(line == null){
    					HighScores5[x] = 0 + "";
    					break;
    				}else{
    					HighScores5[x] = line;
    				}
    			}
    		}catch(Exception e){}
    		
    		
    		try{
    			for(int x = 0; x < 10; x++){
    				String line = timedScanner5.nextLine();
    				if(line == null){
    					timedHighScores5[x] = 0 + "";
    					break;
    				}else{
    					timedHighScores5[x] = line;
    				}
    			}
    		}catch(Exception e){}
    	}
    	
    	public void rewrite(int newScore){
    		if(!usingTimer && !using5){
    			for(int x = 0; x < 10; x++){
    				if(newScore > Integer.parseInt(normalHighScores[x])){
    					for(int xx = 9; xx > x; xx--){
    						normalHighScores[xx] = normalHighScores[xx -  1];
    					}
    					normalHighScores[x] = newScore + "";
    					break;
    				}
    			}
    			for(int x = 0; x < 10; x++){
    				addToFile(normalHighScores[x]);
    			}
    		}else if(usingTimer && !using5){
    			for(int x = 0; x < 10; x++){
    				if(newScore > Integer.parseInt(timedHighScores[x])){
    					for(int xx = 9; xx > x; xx--){
    						timedHighScores[xx] = timedHighScores[xx -  1];
    					}
    					timedHighScores[x] = newScore + "";
    					break;
    				}
    			}
    			for(int x = 0; x < 10; x++){
    				addToFile(timedHighScores[x]);
    			}
    		}else if(!usingTimer && using5){
    			for(int x = 0; x < 10; x++){
    				if(newScore > Integer.parseInt(HighScores5[x])){
    					for(int xx = 9; xx > x; xx--){
    						HighScores5[xx] = HighScores5[xx -  1];
    					}
    					HighScores5[x] = newScore + "";
    					break;
    				}
    			}
    			for(int x = 0; x < 10; x++){
    				addToFile(HighScores5[x]);
    			}
    		}else if(usingTimer && using5){
    			for(int x = 0; x < 10; x++){
    				if(newScore > Integer.parseInt(timedHighScores5[x])){
    					for(int xx = 9; xx > x; xx--){
    						timedHighScores5[xx] = timedHighScores5[xx -  1];
    					}
    					timedHighScores5[x] = newScore + "";
    					break;
    				}
    			}
    			for(int x = 0; x < 10; x++){
    				addToFile(timedHighScores5[x]);
    			}
    		}
    		read();
    	}
    	
    	public void draw(Graphics g){
    		g.setFont(new Font("TimesRoman", Font.PLAIN, 18));
    		g.setColor(Color.black);
    		if(!usingTimer && !using5){
    			g.drawString("Normal Highscores: ", 200, 300);
    			for(int x = 0; x < 10; x++){
    				g.drawString(normalHighScores[x], 200, 320 + (20 * x));
    			}
    		}else if(usingTimer && !using5){
    			g.drawString("Timed Highscores: ", 200, 300);
    			for(int x = 0; x < 10; x++){
    				g.drawString(timedHighScores[x], 200, 320 + (20 * x));
    			}
    		}else if(!usingTimer && using5){
    			g.drawString("5-Block Challenge Highscores: ", 200, 300);
    			for(int x = 0; x < 10; x++){
    				g.drawString(HighScores5[x], 200, 320 + (20 * x));
    			}
    		}else if(usingTimer && using5){
    			g.drawString("Timed 5-Block Challenge Highscores: ", 200, 300);
    			for(int x = 0; x < 10; x++){
    				g.drawString(timedHighScores5[x], 200, 320 + (20 * x));
    			}
    		}
    	}
    	
    	public void reset(){
    		for(int x = 0; x < 10; x++){
    			normalHighScores[x] = 0 + "";
    			timedHighScores[x] = 0 + "";
    			HighScores5[x] = 0 + "";
    			timedHighScores5[x] = 0 + "";
    		}
    		usingTimer = false;
    		using5 = false;
    		rewrite(0);
    		usingTimer = true;
    		rewrite(0);
    		usingTimer = false;
    		using5 = true;
    		rewrite(0);
    		usingTimer = true;
    		rewrite(0);
    	}
    }
    Last edited by Norm; 04-01-2012 at 05:08 PM. Reason: QUOTE to CODE

  9. #89
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    \Blocks\NormalHighScores.txt (The system cannot find the path specified)
    Where is the file located? Do you have the correct path?
    To see where the program is looking for the file, create a File object with the path and print out the value of the absolute path for the file object.
    java.lang.NullPointerException
    at Tetris.HighScores.addToFile(HighScores.java:115)
    look at line 115 and see what variable is null on that line. Use println to print out the values if you can not tell which one.
    Then backtrack in the code to see why that variable does not have a valid value.

    FIX THIS:
    This is bad: }catch(Exception e){} and catch (FileNotFoundException e){}
    All catch blocks should have a call to the printStackTrace() method in them.
    If you don't understand my response, don't ignore it, ask a question.

  10. #90
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Line 115 is:
    Java Code:
                    System.out.println(writer.toString());
    I added the printStackTrace to all the try and catch areas. I thought at first you just wanted it for that area where the problem was.

    Ahh. The location of the file was here:

    C:\Users\Admin\AppData\Local\Mozilla Firefox\.\Blocks\NormalHighScores.txt
    This is definetly not the right path so what do you think I should do?

  11. #91
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    The null variable on line 115 must be writer.

    You will have to use an absolute path not a relative path.
    If you don't understand my response, don't ignore it, ask a question.

  12. #92
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    So I tested it with a few of them and it seems to work. I'm not sure until I edit the whole thing.

    So if that all goes well, all I need to know is if there is any way I can easy make it reachable on a USB stick without having to make a new .java.policy file on each computer and changing the file location.

    EDIT: And it works!
    Last edited by LePotatoeProgrammer; 04-01-2012 at 06:49 PM.

  13. #93
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    This won't be the solution if you want to use the program on many different PCs. Each PC will have to be set up as you have done here. The permissions can be given by putting the classes in a jar file and signing it.
    The file location will have to be the same.
    If you don't understand my response, don't ignore it, ask a question.

  14. #94
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    So how do you sign a jar file? And yes I am using a jar file right now.

  15. #95
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    Take a look at the tutorial. Somewhere it talks about it.
    The Really Big Index
    Find Applet and read on. There are several places about applets and security.
    If you don't understand my response, don't ignore it, ask a question.

  16. #96
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Isn't there something where you can find the location of the classes? It could help make things more portable.

  17. #97
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    Can you explain what you are looking for?
    If you don't understand my response, don't ignore it, ask a question.

  18. #98
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Like a string making it's value equal to where the classes are put using maybe something with System and then use it as a place for the files which need to be read at there specific location. So it can all just be in one folder and no matter where you put it, it would still work. Did that help at all?

  19. #99
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Java Applet Not Running on html.

    Applets can get values from the HTML where they are loaded from via PARAM tags. Is that what you are looking for?

    The use.home property could be used to locate a folder on a PC

    If you want to read an unchanging file, put it in the jar file and use getResource() to find it.
    If you don't understand my response, don't ignore it, ask a question.

  20. #100
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Well the 1st one wasn't really what I wanted, the second doesn't seem to be too useful. Could you explain the third one to me?

Page 5 of 6 FirstFirst ... 3456 LastLast

Similar Threads

  1. java applet not running when accessed from web
    By jobud9 in forum New To Java
    Replies: 3
    Last Post: 01-22-2012, 02:03 AM
  2. Replies: 7
    Last Post: 12-18-2011, 04:13 AM
  3. Applet Running in Java not from Cmd
    By vin_eets in forum Java Applets
    Replies: 1
    Last Post: 03-29-2011, 04:08 PM
  4. Running as Java Applet in eclipse
    By atomant in forum New To Java
    Replies: 0
    Last Post: 12-05-2010, 02:22 AM
  5. Java Applet Not Running
    By kahaj in forum Java Applets
    Replies: 4
    Last Post: 10-08-2009, 12:11 AM

Tags for this Thread

Posting Permissions

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