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 2 of 2

Thread: Getting error as "cannot be resolved to a type"

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting error as "cannot be resolved to a type"

    Hey guys, need some GUI help again.

    Getting error: Encode cannot be resolved to a type on Line no. 25

    where am I doing wrong ?


    Here is my code:
    import java.awt.FlowLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.imageio.ImageIO;
    import javax.swing.*;
     
    import java.io.*; 
     
    import javax.swing.filechooser.FileFilter;
     
    import java.awt.*; 
    public class Hashnain extends JFrame{
     
    	JMenuBar menuBar;
    	   JMenu menu;
    	   JMenuItem menuItem1;
    	   JMenuItem menuItem2;
    	   JMenuItem menuItem3;
    	   JFileChooser c = new JFileChooser();
    	   private JTextArea textArea;
    	   private JLabel label;
    	   private JButton imo;
    	   private JButton enco;
    	  private Image imo1;
    	  private Encode en4;
    	private String			stat_path = "";
    	private String			stat_name = "";
     
    	   Filt im = new Filt();
    	   Model1 mo = new Model1();
     
       public Hashnain(){
          super("The title");
          setLayout(new FlowLayout());
     
          //Create the menu bar.
          menuBar = new JMenuBar();
     
          //Build the first menu.
          menu = new JMenu("Guide");
          menuItem1 = new JMenuItem("Help");
          menuItem2 = new JMenuItem("About");
          menuItem3 = new JMenuItem("Exit");
          imo1=new Image();
          en4 = new Encode();
         imo = new JButton("Select image file");
         enco = new JButton("Encode");
          imo.addActionListener(imo1);
          enco.addActionListener(en4);
     
          menu.add(menuItem1);
          menu.add(menuItem2);
          menu.add(menuItem3);
          add(menu);
          menuBar.add(menu);
          add(menuBar);
    add(imo);
       }
     
       private class Image implements ActionListener
    	{
    		/*
    		 *handles the click event
    		 *@param e The ActionEvent Object
    		 */
    		public void actionPerformed(ActionEvent e)
    		{
    	//show the decode view
    			JFileChooser chooser = new JFileChooser();
    			chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    			chooser.setFileFilter(new Filt());
    			int returnVal = chooser.showOpenDialog(imo);
    			if (returnVal == JFileChooser.APPROVE_OPTION){
    				File directory = chooser.getSelectedFile();
    				try{
    					String image = directory.getPath();
    					stat_name = directory.getName();
    					stat_path = directory.getPath();
    				}
    				catch(Exception except) {
    				//msg if opening fails
    				JOptionPane.showMessageDialog(imo, "The File cannot be opened!", 
    					"Error!", JOptionPane.INFORMATION_MESSAGE);
    				}
    			}
    		}
       private class Encode implements ActionListener{
     
          public void actionPerformed(ActionEvent eq)
             {
     
            	 JFileChooser chooser = new JFileChooser();
     			chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
     			chooser.setFileFilter(new Filt());
            }
     
      	}
     
     
    				}
     			}
     
    Main class:
     
    import javax.swing.JFrame;
    import java.awt.*;
     
    public class Fish {
       public static void main(String[] args){
     
          Hashnain obj= new Hashnain();
          obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          obj.setSize(350, 100);
          obj.setVisible(true);
       }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,647
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Getting error as "cannot be resolved to a type"

    Make sure the Encode class is in scope where you are trying to reference it.
    The formtting of the code makes it hard to read and understand. The {}s are not properly placed.
    Could be a tabs vs spaces being used to control indentations issue.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Error message "Type result cannot be resolved or is not a field"
    By asreall in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 28th, 2012, 07:40 AM
  2. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  3. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  4. "The import ___ cannot be resolved" (stupid noob question)
    By RobG in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 18th, 2010, 02:09 PM
  5. Replies: 4
    Last Post: June 18th, 2009, 09:23 AM