Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Compilation Error

Avatar of Smock
Smock asked on
Java
8 Comments1 Solution223 ViewsLast Modified:
I found this code courtesy of http:
 I tried to build it but i kept getting the error below:

please help:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
      Type mismatch: cannot convert from element type Object to SearchName

Please help.
import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;

public class SearchName extends JFrame {
        static String name;
        static String age;

        public SearchName() {
        }

        public SearchName(String name, String age) {
                SearchName.name = name;
                this.age = age;
        }

        public String getName() {
                return name;
        }

        public String getAge() {
                return age;
        }

        public static void main(String[] args) {
                SearchName search = new SearchName();
                JButton button = new JButton("Search");
                JPanel panel = new JPanel();
                panel.add(button);
                search.add(panel);
                search.setSize(300, 60);
                search.setVisible(true);
                ActionListener actionListener = new ActionListener() {
                        public void actionPerformed(ActionEvent actionEvent) {
                                String n = JOptionPane.showInputDialog(null, "Enter name");
                                try {
                                        FileInputStream fstream = new FileInputStream(
                                                        "studentRecord.txt");
                                        DataInputStream in = new DataInputStream(fstream);
                                        BufferedReader br = new BufferedReader(
                                                        new InputStreamReader(in));
                                        String strLine;
                                        ArrayList list = new ArrayList();
                                        while ((strLine = br.readLine()) != null) {
                                                list.add(strLine);
                                        }
                                        Iterator itr;
                                        for (itr = list.iterator(); itr.hasNext();) {
                                                String str = itr.next().toString();
                                                String[] splitSt = str.split(" ");
                                                String id = "", name = "", age = "";
                                                for (int i = 0; i < splitSt.length; i++) {
                                                        id = splitSt[0];
                                                        name = splitSt[1];
                                                        age = splitSt[2];
                                                }
                                                ArrayList alist = new ArrayList();
                                                alist.add(new SearchName(name, age));
                                                for (SearchName s : alist) {
                                                        if (n.equals(s.getName())) {
                                                                System.out.println("Name Age ");
                                                                System.out.print(s.getName() + " " + s.getAge());
                                                        }
                                                }
                                        }
                                } catch (Exception e) {
                                }
                        }
                };

                button.addActionListener(actionListener);
        }
}
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers