Page 2 of 6 FirstFirst 1234 ... LastLast
Results 21 to 40 of 101
  1. #21
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    I tried the jar but the same error appeared of where the files cannot be used.
    java.security.AccessControlException: access denied (java.io.FilePermission .\Blocks\NormalHighScores.txt read)
    at java.security.AccessControlContext.checkPermission (Unknown Source)
    at java.security.AccessController.checkPermission(Unk nown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at Tetris.HighScores.<init>(HighScores.java:23)
    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.security.AccessControlException: access denied (java.io.FilePermission .\Blocks\NormalHighScores.txt read)
    Exception in thread "Thread-12" java.lang.NullPointerException
    at Tetris.Tetris.run(Tetris.java:39)
    at java.lang.Thread.run(Unknown Source)
    I guess I could try saving the text files with no period but instead C:/ or another drive unless you have a better idea.

  2. #22
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    What did the test with the File class do? Did ir print out anything?
    Try using the File class with other files and see what happens.

  3. #23
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    I don't exactly see the point of printing out things if the only thing that's going wrong is shown by the exception because it shows which line and why.

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    you print things out to see what works and to see the values the computer sees. To get useful information to help solve the problem.

    Its only a suggestion because I thought you were here to get help. The more info that is available about what is happening in your program the more progress that can be made.
    No new information, then no progress.
    If you don't understand my response, don't ignore it, ask a question.

  5. #25
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Could you give an example of what I could print out in this case though?
    Line 23 is this(where the exception occurs):
    scanner = new Scanner(new File("./Blocks/NormalHighScores.txt"));

  6. #26
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    Move the File object outside of the Scanner and make a File object: File aFile = new File("./Blocks/NormalHighScores.txt");
    Print the absolute path for aFile
    If you don't understand my response, don't ignore it, ask a question.

  7. #27
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Good idea. I'll try that out.


    EDIT: So I tried it out and apparently it wasn't the File object the is breaking the code. And the scanner object was making the problem. So what should I do now?
    Last edited by LePotatoeProgrammer; 03-18-2012 at 12:06 AM. Reason: I tested Norm's awesome idea out.

  8. #28
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    What was printed?
    What was the path to the file?
    If you don't understand my response, don't ignore it, ask a question.

  9. #29
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Oh. It printed normal words before and after the file object was created. Then I tried printing out the path and it gave this error:
    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    at java.security.AccessControlContext.checkPermission (Unknown Source)
    at java.security.AccessController.checkPermission(Unk nown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPropertyAccess(Unkn own Source)
    at java.lang.System.getProperty(Unknown Source)
    at java.io.Win32FileSystem.getUserPath(Unknown Source)
    at java.io.Win32FileSystem.resolve(Unknown Source)
    at java.io.File.getAbsolutePath(Unknown Source)
    at Tetris.HighScores.<init>(HighScores.java:25)
    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.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    Exception in thread "Thread-12" java.lang.NullPointerException
    at Tetris.Tetris.run(Tetris.java:39)
    at java.lang.Thread.run(Unknown Source)
    Also, I figured you wanted to see the file controlling code so here it is:
    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("file creating");
    		File test = new File("./Blocks/NormalHighScores.txt");
    		System.out.println("file created");
    		System.out.println(test.getAbsolutePath());
    		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){}
    		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 {
    				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);
    	}
    }

  10. #30
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    Your code does not have permission to look at the path you put in the File object.
    Now try different paths in the File object to see if any of them will print. There does not need to be a file there.
    For example try: new File("test.txt");

    Are you executing the applet from a signed jar file?
    If you don't understand my response, don't ignore it, ask a question.

  11. #31
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    What's a signed jar file?

    Also,I'm working on the paths right now in case your wondering.

  12. #32
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    You "sign" a jar file as a way to give the java classes in the jar file permissions to do things the are not allowed to applets.
    Take a look at the tutorial: Observe Applet Restrictions (The Java™ Tutorials > Security Features in Java SE > Quick Tour of Controlling Applets)
    If you don't understand my response, don't ignore it, ask a question.

  13. #33
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    Ok. I'll see if I can fix things by signing it.

    Also, I did the "test.txt" and it came out with the same error.

  14. #34
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    I can not get the call to the File class's getAbsolutePath() to fail on my system with any browser.
    EDIT: My .java.policy file has:
    permission java.util.PropertyPermission "*", "read";


    When I add a Scanner class object to read the file, it works in FireFox and fails in Chrome and IE.

    What browsers have you tried it with?
    Last edited by Norm; 03-18-2012 at 06:33 PM.
    If you don't understand my response, don't ignore it, ask a question.

  15. #35
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    I was mostly trying with chrome. I'll try firefox.

    Same error.

    So how do you sign a class?

    I went to the properties of the jar and it says it has permission to read and write and modify and read &execute and full control.
    Last edited by LePotatoeProgrammer; 03-18-2012 at 06:25 PM. Reason: Figuring stuff out.

  16. #36
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    I dont have a link to a site that tells you how to sign a jar file. Here is a link that talks about it.
    Signing JAR Files Only When Necessary (The Java™ Tutorials > Deployment > Deployment In-Depth)

    Look at this:
    http://docs.oracle.com/javase/tutori...r/signing.html

    Also Try google.

    I found out why getAbsolutePath worked for me: I have an entry in my .java.policy file that gave it permission:
    permission java.util.PropertyPermission "*", "read";
    Last edited by Norm; 03-18-2012 at 06:35 PM. Reason: found link
    If you don't understand my response, don't ignore it, ask a question.

  17. #37
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    How do you give that permission?

  18. #38
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    Use the policytool to create and update the .java.policy file.
    On my Win7 system the file's location:
    C:\Users\Norm\.java.policy

    The open codebase entry:

    grant {
    permission java.lang.RuntimePermission "modifyThread";
    permission java.lang.RuntimePermission "loadLibrary.HelloNative";
    permission java.util.PropertyPermission "*", "read";
    permission java.lang.RuntimePermission "modifyThreadGroup";
    permission java.io.FilePermission "E:/Java/Java-1_6_0/docs", "read";
    };
    If you don't understand my response, don't ignore it, ask a question.

  19. #39
    Join Date
    Mar 2012
    Posts
    54
    Rep Power
    0

    Default Re: Java Applet Not Running on html.

    I can't seem to find that in my files. I also have the windows 7 though. I'll try searching for them because I have a few named that. Is it a txt file?

  20. #40
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Java Applet Not Running on html.

    You have to create the .java.policy file.
    If you don't understand my response, don't ignore it, ask a question.

Page 2 of 6 FirstFirst 1234 ... 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, 03:03 AM
  2. Replies: 7
    Last Post: 12-18-2011, 05:13 AM
  3. Applet Running in Java not from Cmd
    By vin_eets in forum Java Applets
    Replies: 1
    Last Post: 03-29-2011, 05:08 PM
  4. Running as Java Applet in eclipse
    By atomant in forum New To Java
    Replies: 0
    Last Post: 12-05-2010, 03:22 AM
  5. Java Applet Not Running
    By kahaj in forum Java Applets
    Replies: 4
    Last Post: 10-08-2009, 01: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
  •