I'm tired, so the answer to this might be obvious but I cannot figure out what is going on. I uploaded the code plus input file. When I ran the code here's what I got:

What do you want to do?
-1 -- quit
1 -- add object
2 -- sort objects by first variable
3 -- sort objects by second variables
4 -- sort variables by third variables
5 -- read file
6 -- write to file
0 -- print objects in array
5
Enter File now:
t.txt
Would you like to add objects to array or delete and store file objects only?(a/d)
d
Could not make out command.
What do you want to do?
-1 -- quit
1 -- add object
2 -- sort objects by first variable
3 -- sort objects by second variables
4 -- sort variables by third variables
5 -- read file
6 -- write to file
0 -- print objects in array
5
Enter File now:
t.txt
Would you like to add objects to array or delete and store file objects only?(a/d)
a
Could not make out command.

nowhere in CollectionofObjects.java is "Could not make out command" so I assume its java telling I messed up somewhere?
Module10.zip

thanks for any help

Recommended Answers

All 5 Replies

No, that error message is in Interface.java

Ok, thanks, I see the message now. But how does it jump back to interface.java? is it because both use system.out and/or interface has main in it?

Well, I didn't actually read the code, I just used grep, so I don't know. Presumably Interface is where the user interface is defined, or something like that, and there's an Interface object in there that handles communication with the user.

It certainly doesn't "jump back to" anything - you have objects, and they pass messages back and forth, and things happen. That's what a Java program is, and what it does. Read the code, it'll tell you everything you need to know.

Alright, yeah I wrote the code and everything but I still haven't learned all the nuances of the language. And it may not be 'jumping back, but it doesn't go past this line:

yui.setA(Integer.parseInt(temp2[0]));

(yui being a temporary holder object of ObjA)
I really don't know what's going on because I've never seen this problem before.
I've uploaded the revised code. All I did was rename a few variables and add a few printlns for error checking.
Module10.zip

I fixed the problem. I got help from Yahoo answers of all places. Just had to use generic exception. Sorry for double post

public void readFile(String ffile, String command)
    {
		String ss;
		filename = ffile;
        boolean done = false;
        try
        {
            File file = new File(filename);
            fileRead = new FileReader(filename);
            reader = new BufferedReader(fileRead);
            if (file.exists())
            {
                if (reader.readLine().compareTo("List of Objects:") != 0)
                {
                    done = true;
                }
                else
                {
                    if (command.compareTo("a") == 0)
                    {
                    }
                    else if(command.compareTo("d") == 0)
                    {
                         stuff = new ObjA[10];
						 size = 0;
                    }
                    else
                    {
                        System.out.println("default is add objects");
                    }
                    while (!done)
                    {
                        try
                        {
                            ss = reader.readLine();
							String[] wh = ss.split(", ");
							done = false;
							try
							{
								ObjA yui = new ObjA(Integer.parseInt(wh[0].substring(3,wh[0].length())),wh[1].substring(3,wh[1].length()),Double.parseDouble(wh[2].substring(3,wh[2].length())));
								if (isUniqueObject(yui))
								{
									try
									{
										stuff[size] = new ObjA();
										stuff[size] = yui;
										size++;
									}
									catch (ArrayIndexOutOfBoundsException e)
									{
										increaseArraySize();
										//repeat code in try statement
										stuff[size] = new ObjA();
										stuff[size] = yui;
										size++;
									}//end catch
								}//end if
							}//end try
							catch (Exception e)
							{
								done = true;
							}
						}//end try
						catch (Exception e)
						{
							done = true;
						}
                    }//end while
                }//end inner else
            }//end if                     
            else
            {
            System.out.println("File not found. Check spelling or make sure its in the right file.");
            }
        }
        catch (IOException e)
        {
            System.out.println("Something is wrong with the stream reader");
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.