|
-
How to use Linked lists and classes......
I was hoping someone could help me with this...I am trying to access methods
of a instance of a class that is stored in the LinkedList object. I can
print out the reference to the object stored in the linked list, but I can't
get to the methods. I have looked at List Iterator in the instance of my
linked list, but am not real sure on how to use it, nor can I find any real
good documentation on it. It also won't let me directly access the element
index using list.size or any of its methods. The code follows...Someone please
help and thanks for any help.
import java.io.*;
import java.util.*;
public class infile
{
public static void main(String [] argv) throws FileNotFoundException
{
String line;
LinkedList list = new LinkedList();
FileReader fr = null;
BufferedReader infile = null;
StringTokenizer t;
fr = new FileReader("fds.txt");
if(fr != null)
{
infile = new BufferedReader(fr);
if(infile == null)
{
System.out.println("Changing to BufferedReader failed");
System.exit(0);
}
}
else
{
System.out.println("File not found");
System.exit(0);
}
try
{
while((line = infile.readLine()) != null)
{
t = new StringTokenizer(line,">");
DbTemplate myFD = new DbTemplate();
String str = t.nextToken();
myFD.setLeftSide(str);
System.out.println(myFD.getLeftSide() );
str = t.nextToken();
myFD.setRightSide(str);
System.out.println(myFD.getRightSide() );
myFD.setfD();
System.out.println(myFD.getFD() );
list.add(myFD);
}//while end
}
catch(IOException e)
{
System.err.println("End of File");
}
System.out.println( "\nlist: " );
for ( int k = 0; k < list.size(); k++ )
{
System.out.print( list.get( k ) + " " );
k.getFD(); // ERROR about int can't be dereferenced
*******I want to print out the leftSide, rightSide, and myFD of class DbTemplate
right here. Thats all.*********
}
}//main end
}//Class end
class DbTemplate
{
private String fD, leftSide, rightSide, oldFD;
public void setfD()
{
fD = getLeftSide() + ">" + getRightSide();
}
public String getFD()
{
return fD;
}
public void setLeftSide(String x)
{
leftSide = x;
}
public String getLeftSide()
{
return leftSide;
}
public void setRightSide(String x)
{
rightSide = x;
}
public String getRightSide()
{
return rightSide;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks