Exceptions and non-static methods
Hi folks,
I'm trying to read a text file from a jar but having a few problems.
My code looks like this
import java.lang.Class.*;
import java.io.*;
publicclass test
{
publicstaticvoid main(String[] args)
{
String result="";
result = getInfo("info.txt");
System.out.println(result);
}
public String getInfo(String fileName)
{
InputStream is = getClass().getResourceAsStream("info.txt");
int temp=0;
char data;
String inforesult ="";
try{
//code to read from inputstream goes here
//removed for forum post
}catch (IOException ioex){
System.out.println("Error reading file.");
}
return inforesult;
}
}
This is really only test code - I intend to rework it into another (functioning) program which currently reads the file from outside the jar.
The problem breaks down as follows:
If I leave thestatic
before main it won't compile - I get non-static method ... cannot be referenced from static context
And if I leave it out, it compiles but doesn't run:
(Exception in thread "main" java.lang.NoSuchMethodError: main)
Any thoughts on what to do?
With thanks in advance,
Conor

