Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ClassLoader.getResourceAsStream + Major problem ;-)

807597Apr 13 2005 — edited Apr 14 2005
Hi,

Please let me know what is worng with this application: I am getting compilation error. The method getResourceAsStream() is a non-static method.

" non-static method func(java.lang.String) cannot be referenced from a static context"

=============================================
import java.io.* ;

public class LoadProp
{
public static void main(String args[])
{
String testname = System.getProperty("propfile");
System.out.println(testname);
func(testname) ;
System.out.println("End Main!") ;
}
public void func(String file )
{
try
{
InputStream is = ClassLoader.getResourceAsStream(file);
System.out.println("File load successful");
}
catch (Exception e)
{
System.out.println("Inside Catch");
throw e;
}
}

}
=====================================

I also implemented the same by creating a new class as below:

class Jms
{
public void func(String file )
{
try
{
InputStream is = ClassLoader.getResourceAsStream(file);
System.out.println("File load successful");
}
catch (Exception e)
{
System.out.println("Inside Catch");
throw e;
}
}

public class LoadProp
{
public static void main(String args[])
{
String testname = System.getProperty("propfile");
System.out.println(testname);
Jms j = new Jms() ;
j.func(testname) ;
System.out.println("End Main!") ;
}
}

Please let me know what is worng with this application .

Thanks
N
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 12 2005
Added on Apr 13 2005
6 comments
348 views