- Joined
- Jan 31, 2010
- Messages
- 1
- Reaction score
- 0
I'm new but I have been searching for the answers to this problem for 2 hours and have just about given up. Every one else's code situation with the same error looks different. Perhaps you guys can help me.
I am attempting to implement a linked queue in java but have the error "non-static method insert(java.lang.String) cannot be referenced from a static context".
linkedqueue.java
jroff.java
Any help would be appreciated
I am attempting to implement a linked queue in java but have the error "non-static method insert(java.lang.String) cannot be referenced from a static context".
linkedqueue.java
Code:
import java.util.NoSuchElementException;
class linkedqueue <Object> {
private class node{
Object value = null;
node link = null;
}
private node front = null;
private node rear = null;
/*
public boolean empty (){
return front == null;
}
*/
// ------- insert new obejct into rear of the list
public void insert (String obj) {
// stub if list is null return null
node previous = null;
// Find the end of the list.
for( node itor = this.front; itor != null; itor = itor.link ){
previous = itor;
};
// Make a new node.
node newnode = new node();
newnode.value = object;
newnode.link = null;
// Insert it at the end of the list or at the head, if empty.
if( previous == null ) this.front = newnode;
else previous.link = newnode;
}
public String remove (){
Object obj = front.value;
String temp = obj.toString();
front = front.link;
return temp;
}
}
jroff.java
Code:
import java.io.*;
import java.util.Scanner;
import static java.lang.System.*;
public class jroff{
final static String STDIN_NAME = "-";
public
static void scanfile (String filename, Scanner infile) {
err.printf ("STUB: filename = %s%n", filename);
for (int linenr = 1; infile.hasNextLine(); ++linenr) {
String line = infile.nextLine(); // get the line
if(line.length()==0){
err.printf (".sp 1%n");
}
else if(line.length()>=1){
char c = line.charAt( 0 );
if(c == '.'){
err.printf ("This line begins with a period.");
}
}
err.printf ("STUB: %s: %4d: \"%s\"%n", filename, linenr, line);
String[] words = line.split ("\\s+"); // split the line by spaces
for (String word: words) {
linkedqueue.insert(word); // <----- error is here
err.printf ("print STUB: word = \"%s\"%n", word);
}
}
}
public static void main (String[] args) {
linkedqueue wordqueue = new linkedqueue ();
if (args.length == 0) {
scanfile (STDIN_NAME, new Scanner (in));
}else {
for (String filename : args) {
if (filename.equals (STDIN_NAME)) {
scanfile (STDIN_NAME, new Scanner (in));
}else {
try {
Scanner scan = new Scanner (new File (filename));
scanfile (filename, scan);
scan.close();
}catch (IOException error) {
auxlib.warn (error.getMessage());
}
}
}
}
}
}
Any help would be appreciated