Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Java Course Issues (Mod 5)

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Course Issues (Mod 5)

    Not sure about proper etiquette or how to best describe my issues, that's where I am at. I am set to graduate this semester baring me passing this class.

    Attached is my current on what is supposed to be a simple problem but I am stuck and have been for awhile. I can figure my way around programing loops, searches, sorting, and most logic type problems. I have two primary issues I continue to get stuck on the proper use of vectors, and the graphical interface and how to use it in the sorting.

    The first file describes the problem the rest is my current progress with the program, I realize I am asking a massive question but on this one I have just hit a major road block. Let's start with the first problem, step three. In the showDirectoryContents method, I am unsure how to properly match the vector types and use it in the sort. Let's start there.
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Course Issues (Mod 5)

    Please post your code here on the forum and some specific questions about the code.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Course Issues (Mod 5)

    Sorry for the delay. Below is the portion of code I am referring to and below that is the portion which is referenced in the code. Code makes a note of Module 3 that working function is at the bottom. My questions an thoughts are:
    After numerous attempts, I still am unsure how to pass back and forth in conjunction with the multidimensional array, that why I added the vector.
    I keep getting "Type mismatch" errors using vectors, I know why I get the error just don't know the fix, and correct way. The function gui.updateListing is expecting a vector, I know the way I am forming my vector is wrong.

    [DirectoryLister.Java]
    	/** Vector of Vectors to store the information for the files/subfolders of the selected folder */
    	//TODO
    	private Vector[][] folderContents = new Vector[100][4];
    ...
    .....
    .....
    ...
     
    	/**
    	 *	Show the directory listing.
    	 *	An error message is displayed if basePath does not represent a valid directory.
    	 * 
    	 *	@param	basePath		the absolute path of a directory in the file system.
    	 */
    	public void showDirectoryContents(String basePath)
    	{
    		// TODO
    		// This method should function exactly as it did in the Module 3 assignment,
    		// except after the selected directory has been enumerated, the contents should be
    		// sorted in ascending order based on the path of the files/subfolders.
     
    		try{
     
    			File path = new File(basePath);
    			if (!path.isDirectory()){
    				throw new IOException();
    			}
    			Vector[] a = new Vector[4] {path.getAbsolutePath(),getSizeString(path.length()),"Folder",formattedDateString(path.lastModified())};
    			gui.updateListing(a);
     
    			String [] tree = path.list();
    			enumerateDirectory(path);
    		}catch(NullPointerException e){
    			JOptionPane.showMessageDialog(null, "No Directory selected.", "ERROR", JOptionPane.ERROR_MESSAGE);
    		}catch(IOException f){
    			JOptionPane.showMessageDialog(null, "No Directory selected.", "ERROR", JOptionPane.ERROR_MESSAGE);
    		}
    	}
     
     
    [GUI.java]
    	/**
    	 *	Update the table with the specified file/folder information.
    	 *	The Vector folderContents is a Vector of Vectors, where each Vector represents the
    	 *	information for each file/folder and occupies a single row in the table.
    	 *
    	 *	Information is displayed in the following order:
    	 *
    	 *		Column 1: absolute path of file or folder
    	 *		Column 2: size of file in kilobytes, or "" for folders
    	 *		Column 3: type - "File" or "Folder"
    	 *		Column 4: date last modified in format: month/day/year hour:minute:second AM/PM
    	 */
    	public void updateListing(Vector folderContents)
    	{
    		clearTable();
     
    		for (Iterator itr = folderContents.iterator(); itr.hasNext(); )
    		{
    			Vector row = (Vector)itr.next();
     
    			tableModel.addRow(new String[] {" " + (String)row.get(0),
    											getSizeString((Long)row.get(1)) + " ",
    											" " + (String)row.get(2),
    											" " + formattedDateString((Long)row.get(3))});
    		}
    	}
     
    [Mod3][DirectoryLister.Java]
    	public void showDirectoryContents(String basePath)
    	{
    		// TODO
    		try{
     
    			File path = new File(basePath);
    			if (!path.isDirectory()){
    				throw new IOException();
    			}
    			gui.updateListing(path.getAbsolutePath(),getSizeString(path.length()),"Folder",formattedDateString(path.lastModified()));
     
    			String [] tree = path.list();
    			enumerateDirectory(path);
    		}catch(NullPointerException e){
    			JOptionPane.showMessageDialog(null, "No Directory selected.", "ERROR", JOptionPane.ERROR_MESSAGE);
    		}
    		catch(IOException f){
    			JOptionPane.showMessageDialog(null, "No Directory selected.", "ERROR", JOptionPane.ERROR_MESSAGE);
    		}
    	}
    Last edited by Norm; March 13th, 2013 at 07:20 AM. Reason: added code tags

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Course Issues (Mod 5)

    Did my last reply not get approved by moderation?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Course Issues (Mod 5)

    I keep getting "Type mismatch" errors
    Please copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Course Issues (Mod 5)

    First issue with vector multiple occurrences of "Type mismatch: cannot convert from String to Vector DirectoryLister.java"
    Next line, with the call I get "The method updateListing(Vector) in the type GUI is not applicable for the arguments (Vector[]) DirectoryLister.java"

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Course Issues (Mod 5)

    Please copy the full text of the error messages and paste it here. The error messages give inportant info about the errors. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Course Issues (Mod 5)

    I guess I am insure what you mean then. I am using eclipse and that is the full text of the error I get when in eclipse. The only extra information is the resource, path, location, and type; which seem unnecessary.

    Example:
    Type mismatch: cannot convert from String to Vector DirectoryLister.java /mod5/src line 133 Java Problem

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Course Issues (Mod 5)

    cannot convert from String to Vector DirectoryLister.java /mod5/src line 133
    What statement is at line 133? The compiler objects to the code trying to convert a String to a Vector.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Course Issues (Mod 5)

    133 Vector[] a = new Vector[4] {path.getAbsolutePath(),getSizeString(path.length( )),"Folder",formattedDateString(path.lastModified( ))};
    134 gui.updateListing(a);

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Course Issues (Mod 5)

    The compiler is complaining that the items in {} are not Vectors. If you wan to put items into a Vector, use the Vector class's add() method.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Issues with my ordering program - if statement issues?
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 31st, 2012, 10:17 PM
  2. ISSUES in java.awt
    By mailkamlesh in forum AWT / Java Swing
    Replies: 2
    Last Post: August 25th, 2011, 09:36 AM
  3. mod 95 vigninere cipher
    By fortune2k in forum Algorithms & Recursion
    Replies: 4
    Last Post: December 5th, 2010, 09:43 PM