ClassLoader.getResourceAsStream + Major problem ;-)
807597Apr 13 2005 — edited Apr 14 2005Hi,
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