aspose file tools*
The moose likes Java in General and the fly likes Method visibility among classes... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Method visibility among classes..." Watch "Method visibility among classes..." New topic
Author

Method visibility among classes...

Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
I'm sure that I'm just missing something very small here. This is more of a method visibility issue than a servlet issue so that is why I'm posting here. I have a servlet class, and I have another class for with DB connecting and RS returning. I'll post the snippets and then describe the error...

My servlet code...



This is just a snippet, I have some 'if' logic below the request.setAttribute, but that doesn't do anything except build a string and blah blah.

Here is the code for the connection class...



That is the whole class with both methods. My error is in the servlet class. In the line that says 'Connection opnConn = opnAS400Conn(url, libraryName, userName, password);' I am getting an error that says...

'The method opnAS400Conn(String, String, String, String) is undefined for the type FormManager'

FormManager is the name of my servlet, opnAS400Conn is the method in my class ConnDB. They are both part of the same package and both classes know that.

Why can't my servlet see that method in the other class?
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
You need to call



Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
Ok. So my code now looks like this...



But it tells me
Default constructor cannot handle exception type Exception thrown by implicit super constructor.
Must define an explicit constructor


I'm going to dig around to figure out why this is, if anyone knows I would surely appreciate the help.
Timothy Frey
Ranch Hand

Joined: Jul 22, 2006
Posts: 56
The problem seems to be in this line of your Servlet class:



Note 2 things about this statement:
- It can throw an Exception
- It is executed by the constructor

I'm not a servlet expert so I don't know whether or not its legal to declare a constructor that can throw an exception. You could probably create the connection in the init() method and try to catch the exception, rethrowing it as a ServletException if needed.
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
Thanks for the reply Tim. That took care of that error. My next question is this...

Down in my doPost I have some 'if' statements. They build a string buffer and then call this...



I use the opnConn that I created in the init() method. But it says opnConn cannot be resolved. Do I need to return it out of my init() method in order for my other methods to see it?
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
I didn't have the right scope. I had to declare

above my init() method. Then the other methods could see it once I initialized it. Everything seems to be going ok for now. I'll know in a couple hours if this is going to work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method visibility among classes...
 
Similar Threads
ArrayList not clearing
BeanInstantiationException
Struggling With Passing Data Between Data Access Class, Business Bean, and Controller
ClassNotFoundException: AS400JDBCDriver
Not authenticating the user