Thread: Text area

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    23
    Rep Power
    0

    Text area


    I'm trying to create a program where i have an array that holds my image names on a split pane and on the other side of the pane it shows a picture of the selected name.This part of the program works fine but i also have a text area on the frame and what i want it to do is display the text file that pairs with the name selected in the split pane(just like the image). When i run the program the image shows but cmd displays an error message of " java.io.FileNotFoundException: \example.txt <The system cannot find the file specified> The picture of example will show where its supposed to but not the text here is part of my code that deals with this...
    Code:
    	public void valueChanged(ListSelectionEvent e)
    	{
    		JList list = (JList)e.getSource();
    		updateLabel(imageNames[list.getSelectedIndex()]);
    
    	}
    	protected void updateLabel (String name)
    	{
    		ImageIcon icon = createImageIcon("/" + name + ".gif");
    		picture.setIcon(icon);
    		if (icon != null)
    		{
    			picture.setText(null);
    		} else {
    			picture.setText("Image not found");
    		}
    		try
    		{
    			FileReader reader = new FileReader("/" + name + ".txt");
    			BufferedReader br = new BufferedReader(reader);
    			fullDes.read( br, null );
    			br.close();
    			fullDes.requestFocus();
    		}
    		catch(Exception e2) {System.out.println(e2); }
    	}
    
    
    
    	protected static ImageIcon createImageIcon(String path)
    	{
    		java.net.URL imgURL = GuideScreen.class.getResource(path);
    		if (imgURL != null)
    		{
    			return new ImageIcon(imgURL);
    		} else {
    			System.err.println("Could't find file: " + path);
    			return null;
    		}
    	}
    (PS fullDes is my textArea).
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    an error message of " java.io.FileNotFoundException: \example.txt
    Is the file in the location that the program is looking for it?

    You can see where the program is looking by creating a File object with the filename and printing the value of the File object's absolute path.

    Also posted at: http://forums.codeguru.com/showthrea...9259-text-area
    Last edited by NormR; August 20th, 2013 at 08:54 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    23
    Rep Power
    0
    The file is in the same directory as the program, the images, i don't know why it's giving me this problem.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    What printed out when you printed the absolute path? Did it show the expected path to the file?
  8. #5
  9. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    Originally Posted by jumpman8947
    The file is in the same directory as the program, the images, i don't know why it's giving me this problem.
    Did you try removing the slash from the beginning of your filename? Typically this is root of the system. That is /example.txt does not indicate a file in the current directory.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    23
    Rep Power
    0
    Thanks for all the replies,

    problem solved, i simply removed the slash "/" and just kept the quotes empty.

IMN logo majestic logo threadwatch logo seochat tools logo