Results 21 to 40 of 101
Thread: Java Applet Not Running on html.
- 03-17-2012, 09:26 PM #21
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
Re: Java Applet Not Running on html.
I tried the jar but the same error appeared of where the files cannot be used.
I guess I could try saving the text files with no period but instead C:/ or another drive unless you have a better idea.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)
- 03-17-2012, 09:30 PM #22
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.
- 03-17-2012, 09:51 PM #23
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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.
- 03-17-2012, 10:05 PM #24
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.
- 03-17-2012, 10:32 PM #25
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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"));
- 03-17-2012, 10:35 PM #26
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 aFileIf you don't understand my response, don't ignore it, ask a question.
- 03-17-2012, 11:00 PM #27
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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-17-2012 at 11:06 PM. Reason: I tested Norm's awesome idea out.
- 03-17-2012, 11:16 PM #28
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.
- 03-18-2012, 03:44 AM #29
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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:
Also, I figured you wanted to see the file controlling code so here it is: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)
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); } }
- 03-18-2012, 01:07 PM #30
Re: Java Applet Not Running on html.
Your code does not have permission to look at the path you put in the File object.java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
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.
- 03-18-2012, 03:59 PM #31
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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.
- 03-18-2012, 04:05 PM #32
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.
- 03-18-2012, 04:07 PM #33
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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.
- 03-18-2012, 04:59 PM #34
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 05:33 PM.
If you don't understand my response, don't ignore it, ask a question.
- 03-18-2012, 05:16 PM #35
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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 05:25 PM. Reason: Figuring stuff out.
- 03-18-2012, 05:34 PM #36
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 05:35 PM. Reason: found link
If you don't understand my response, don't ignore it, ask a question.
- 03-18-2012, 05:47 PM #37
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
Re: Java Applet Not Running on html.
How do you give that permission?
- 03-18-2012, 05:56 PM #38
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.
- 03-18-2012, 06:33 PM #39
Member
- Join Date
- Mar 2012
- Posts
- 54
- Rep Power
- 0
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?
- 03-18-2012, 06:36 PM #40
Similar Threads
-
java applet not running when accessed from web
By jobud9 in forum New To JavaReplies: 3Last Post: 01-22-2012, 02:03 AM -
Problem running Applet in IE but works when running just Java in Netbeans?
By rodneyc8063 in forum Java AppletsReplies: 7Last Post: 12-18-2011, 04:13 AM -
Applet Running in Java not from Cmd
By vin_eets in forum Java AppletsReplies: 1Last Post: 03-29-2011, 04:08 PM -
Running as Java Applet in eclipse
By atomant in forum New To JavaReplies: 0Last Post: 12-05-2010, 02:22 AM -
Java Applet Not Running
By kahaj in forum Java AppletsReplies: 4Last Post: 10-08-2009, 12:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks