Java - Error: no suitable method found for add(int, java.lang.String) -
I'm in the middle of homework work and I'm stuck. At this point in my code, I think that I should have a GUI window that opens and allows me to type "inserted text number". Notice is not going anywhere but at this point, If I pass through the problem then it will be in a linked list. I am getting two of the same error for the lines. Add (index, element); And I can not seem to get past it, there is no suitable method for the error "add (int, java. string string)". Code is below, please advise. To clarify - this will not be a method error because it is a linked list. There should not be any way involved.
import java.awt. *; Import java.awt.event. *; Import javax.swing. *; Import java.util. *; Import java.util.Scanner; Import java.util.LinkedList; Public class TopTenList JFrame {Private TopTenList tt; See the Private JTextArea list; Private JTextField cmdTextField; Private JTextField resultsTestfield; // This GUI window is the code for the public toptist () {tt = new TopTenList ()); ListView = new JTextArea (); CmdTextField = new JTextField (); // Command text field JPNL CMD Panel = Create new ZIPLine (new grid layout (1,2)) for panel and label; CmdPanel.add (new JLabel ("Enter new score:")); CmdPanel.add (cmdTextField); Add (CMDPanel, Border Layout. North); CmdTextField.addActionListener (New CmdTextListener ()); // set the frameset set ("top ten scoreheaders"); // Window Title Set DefaultCallonation (JFrame.EXIT_ON_CLOSE); Behavior on / Close Pack; SetVisible (true); // Add text frame (listView) between windows Add // Add frame; ListView.setEditable (wrong); ListView.setBackground (Color.WHITE); } // Private class Users who respond to new scores recorded by the private class, CmdTextListener implements ActionListener {Static cmdText = cmdTextField.getText (); Scanner sc = new scanner (CMDtext); String cmd = sc.next (); If (cmd.equals ("insert")) {if (sc.hasNextInt ()) {// index element int index = sc.nextInt () add; String element = sc.next (); Tt.add (index, element); } Else {// add element string element = sc.next (); Tt.add (element); } ListView.setText (tt.toString ()); Pack (); Return; }}} // The main method to run the top ten list public static zero main (string [] args {new topilist (); }}
You have never created (int i, object o) In any of your classes, you are treating tt as a list when it is not so you will need to make a method or you try to apply the list class Can.
Comments
Post a Comment