Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31
Like Tree2Likes

Thread: Comparing Strings Application

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    what type of variable is stringApp to be?
    You assigned a value to stringApp in post#18. That is the type it is supposed to be

    I believe it would need to be listed under the class
    Why? What method needs to get to it?

  2. #22
    broo7198 is offline Member
    Join Date
    Aug 2011
    Location
    West Virginia
    Posts
    38
    Rep Power
    0

    Default

    well in my current code:

    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    
    //Main class
    public class StringApplication {
    
    	// Variables
    	 private String mainString;
    	 private String secondaryString;
    	 private int idex1;
    
    
    
    	// JOptionPane Input class
    	public void GetInput() {
    
    
    			 mainString = JOptionPane.showInputDialog("Enter a String");
    
    			 secondaryString = JOptionPane.showInputDialog("Enter Another String");
    
    }
    
    	// use indexOf method to compare strings
        public void checkStringContains() {
    
    
    		System.out.println("About to check \"" + mainString + "\" with \"" + secondaryString + "\"");
    
            int index1 = mainString.indexOf(secondaryString);
    
            if (index1 != -1)
                System.out.println("The string contains the substring " + secondaryString);
            else
                System.out.println("The string does not contain the substring " + secondaryString);
        }
    	// main method
        public static void main(String[] args) {
    
    		 stringApp = new StringApplication();
    
        }
    I have a new variable stringApp assigned to a new StringApplication(); however when I try to compile i get an error


    "C:\Users\broo7198\Documents\StringApplication.jav a:40: cannot find symbol
    symbol : variable stringApp
    location: class StringApplication
    stringApp = new StringApplication();
    ^
    1 error

    Tool completed with exit code 1"


    I suppose only the main method needs to access this variable, but I still do not know how to call the GetInput and checkStringContains methods in reference to this new variable

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    You need to define the stringApp variable. The compiler can not find its definition.
    The assignment statement is giving it a value, but it also needs to be defined.

    For example this defines the idex1 variable:
    private int idex1;

    and this defines the index1 variable:
    int index1 = mainString.indexOf(secondaryString);

    See the <data type of int> at the beginning of the source line.

  4. #24
    broo7198 is offline Member
    Join Date
    Aug 2011
    Location
    West Virginia
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    You need to define the stringApp variable. The compiler can not find its definition.
    The assignment statement is giving it a value, but it also needs to be defined.

    For example this defines the idex1 variable:
    private int idex1;

    and this defines the index1 variable:
    int index1 = mainString.indexOf(secondaryString);

    See the <data type of int> at the beginning of the source line.
    right, but when I try to define the variable with String or int ..the compiler will not accept any of them. "Incompatible types"

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    What is the type of the data are you assigning to the variable you are having problems with? Look to the right of the = sign. What to you see there???
    broo7198 likes this.

  6. #26
    broo7198 is offline Member
    Join Date
    Aug 2011
    Location
    West Virginia
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What is the type of the data are you assigning to the variable you are having problems with? Look to the right of the = sign. What to you see there???
    haha! finally figured it out. Thank you for being so patient

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    I was sure we'd get you there eventually.
    broo7198 likes this.

  8. #28
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I missed a lot while I was asleep...:)

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    No excuses. Either you stay up and post messages, or some one else will do it for you.

  10. #30
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I should just try and set up an auto poster..."Please use code tags and give us the full stack trace" should cover the bulk of what we get.
    :)

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    I must enter that 50 times a day. I have many of those standard responses on a tool with a menu to select the message and copy it to the clipboard.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Comparing Strings
    By Adomini in forum New To Java
    Replies: 3
    Last Post: 02-17-2011, 12:20 AM
  2. need in help in comparing Strings
    By jaq in forum New To Java
    Replies: 1
    Last Post: 11-25-2009, 01:06 PM
  3. comparing strings
    By diggitydoggz in forum New To Java
    Replies: 7
    Last Post: 12-23-2008, 04:40 AM
  4. Comparing Strings
    By souFrag in forum Advanced Java
    Replies: 5
    Last Post: 05-21-2008, 09:03 AM
  5. Comparing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •