Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

java.lang.IllegalAccessException

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error when I run my servlet:
java.lang.IllegalAccessException: tryTransform
I thought that it would be solved by making classes public, but to no avail.
In the system exception, there is this bit:
Exception in init tryTransform - java.lang.IllegalAccessException: tryTransform
I started my class like this:
public class tryTransform
Init is simply this:
public void init(ServletConfig config)
{
System.out.print("got here2");
}
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is your code in the servlet. Does this tryTransform is a bean class, and get called in a servlet? If you treat tryTransform as a servlet, then that is a problem. All servlet need to extends HttpServlet, and have init(), doGet(), and doPost().
 
padraig cooney
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code:
public class tryTransform extends HttpServlet{

public String HTML = new String();
public void init(ServletConfig config)
{
System.out.print("tryTransform servlet is initialised");
}

public void service(HttpServletRequest req,HttpServletResponse resp)
{
System.out.print("got here3");
try
{
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
resp.setStatus(HttpServletResponse.SC_OK);
TransformerFactory tfactory = TransformerFactory.newInstance();

// Create a transformer for the stylesheet.
Transformer transformer
= tfactory.newTransformer(new StreamSource("PNRetc.xsl"));

// Transform the source XML to System.out.

OutputStream outHTML = null;

transformer.transform( new StreamSource("presentResponseFF1.xml"),
new StreamResult(outHTML));

HTML = outHTML.toString();

out.print(HTML);

}
catch(Exception e)
{
System.out.println("Error occured");
}


}
}
 
padraig cooney
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code:
public class tryTransform extends HttpServlet{

public String HTML = new String();
public void init(ServletConfig config)
{
System.out.print("tryTransform servlet is initialised");
}

public void service(HttpServletRequest req,HttpServletResponse resp)
{
System.out.print("got here3");
try
{
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
resp.setStatus(HttpServletResponse.SC_OK);
TransformerFactory tfactory = TransformerFactory.newInstance();

// Create a transformer for the stylesheet.
Transformer transformer
= tfactory.newTransformer(new StreamSource("PNRetc.xsl"));

// Transform the source XML to System.out.

OutputStream outHTML = null;

transformer.transform( new StreamSource("presentResponseFF1.xml"),
new StreamResult(outHTML));

HTML = outHTML.toString();

out.print(HTML);

}
catch(Exception e)
{
System.out.println("Error occured");
}


}
}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, for one thing, if you use this form of init:
public void init(ServletConfig config)
{
super.init( config ) ; // MUST HAVE THIS!!!
System.out.print("got here2");
}
Also - every time I see this I cringe:
catch(Exception e)
{
System.out.println("Error occured");
}
You are throwing away valuable information! At least do this:
catch(Exception e){ e.printStackTrace( System.err );
}
Bill

------------------
author of:
 
Get out of my mind! Look! A tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic