Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

trouble constructing new URLClassLoader

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an applet I'm making I have the following code:

import java.net.*;

public class fileloader extends javax.swing.JApplet {

public fileloader() {
String fileNameString = "http://members.aol.com/davllew/";
URL fileAddressURL = new URL(fileNameString);
URLClassLoader fileClassLoader = new URLClassLoader(fileAddressURL);
}

}

basically I want to load a class from a location in the string fileNameString, but the compiler is giving me an error on the URLClassLoader line. I get the following error:
fileloader.java [8:1] cannot resolve symbol
symbol : constructor URLClassLoader (java.net.URL)
location: class java.net.URLClassLoader

I've asked quite a lot of questions on this forum recently, mainly because I'm pretty new to java, so I hope the questions aren't offensively simple!
cheers
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason you are seeing "cannot resolve symbol" messages is because you are attempting to call a constructor of URLClassLoader which takes a single URL object as its parameter. URLClassLoader doesn't have a constructor like that, hence the confusion. You need to pass it an array of URL objects.

And don't worry - there is no such thing as an "offensively simple" question. Keep posting as many as you need. All questions are valid, because you don't know the answer . Questions only get a frosty response here when they are poorly asked or demanding, neither of which is true of this question.
 
David Llewellyn
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I now have the following code:

import java.net.*;

public class fileloader extends javax.swing.JApplet {

public fileloader() throws Exception{
String fileNameString = "http://members.aol.com/davllew/";
URL[] urlToLoadFrom = new URL[]{new URL(fileNameString)};
URLClassLoader classesToLoad = new URLClassLoader(urlToLoadFrom);
}

}

and I now get the following error:
java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader)

I think this must be because Im using an applet. If it is, how can I get around this (maybe by changing the policy files)?
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by David Llewellyn:

I think this must be because Im using an applet. If it is, how can I get around this (maybe by changing the policy files)?



You are correct. Take a look at The Java Tutorial: Applet Security Restrictions for the basics and Advanced Programming for the Java 2 platform: Signed Applets for another option.
 
David Llewellyn
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to get around the security issues ive decided to allow my own URL to be granted all security permissions in a policy file like this:

grant codeBase "http://www.mywebpage.com/myApplets/"; {
permission java.security.AllPermission;
};

To make this work I know (or at least I think I know :confused that I have to add the policy file's url to my java.security file, correct?
When i tried loading it with a text editor, It looked like babble.
should I just add the url to the end of the java.security file like this:

policy.url.3=file:/C:/myapplet/mypolicy

?? I tried googleing first, but couldn't find out exactly how to do this.
cheers
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic