UEGENT !!! RandomAccessFile, help

I get the following error while compiling:
No enclosing instance of type db is accessible. Must qualify the allocation with an enclosing instance of type db (e.g. x.new A()
where x is an instance of db ).

The return statement of the readStudent() method is where the problem
lies, can anybody assist please.

[CODE]

public class db {

public static Student readStudent(RandomAccessFile f) {
try {
String name = readFixedString(f, NAME_SIZE);
int studid = f.readInt();
int code = f.readInt() ;
return ( new Student(name, studid, code) );
}catch(Exception e) {
return null ;
}
}

class Student {
public student(String n, int j, int x ) {
//Statement
}
}
}

[/CODE]

Comments

  • : I get the following error while compiling:
    : No enclosing instance of type db is accessible. Must qualify the allocation with an enclosing instance of type db (e.g. x.new A()
    : where x is an instance of db ).
    :
    : The return statement of the readStudent() method is where the problem
    : lies, can anybody assist please.
    :
    : [CODE]
    :
    : public class db {
    :
    : public static Student readStudent(RandomAccessFile f) {
    : try {
    : String name = readFixedString(f, NAME_SIZE);
    : int studid = f.readInt();
    : int code = f.readInt() ;
    : return ( new Student(name, studid, code) );
    : }catch(Exception e) {
    : return null ;
    : }
    : }
    :
    : class Student {
    : public student(String n, int j, int x ) {
    : //Statement
    : }
    : }
    : }
    :
    : [/CODE]
    :
    Return is not a method, but a reserved word. It doesn't need any brackets around the value it returns.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion