Welcome to Dream.In.Code
Become a Java Expert!

Join 150,375 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,613 people online right now. Registration is fast and FREE... Join Now!




cannot find symbol constructor error, but can't seem to find the p

 
Reply to this topicStart new topic

cannot find symbol constructor error, but can't seem to find the p

robthuff
17 Feb, 2008 - 08:23 PM
Post #1

New D.I.C Head
*

Joined: 17 Feb, 2008
Posts: 1

Here is the program and I'm having difficulties finding symbol constructor ReverseString, but don't know why.
Main.java
CODE

package edu.uhcl.sce.palindrome;

import javax.swing.JOptionPane;

public class Main {
    public static void main(String args[]){
        StringBuilder sb = new StringBuilder();
        String s1 = JOptionPane.showInputDialog("Please enter the phrase:");
        for(int i=0; i<s1.length(); ++i)
    {
            if(Character.isLetter(s1.charAt(i)))
        {
               sb.append(s1.charAt(i));
        }
    }
        String s2 = sb.toString();
        String sUpper = s2.toUpperCase();
        System.out.println(sUpper);
        ReverseString revString = new ReverseString(sUpper);
        System.out.println(revString);
        if(sUpper.equals(revString)){
              System.out.println("is palindrome");}
                  else                  
              System.out.println("is not palindrome");
            
        
    }
}



and the ReverseString.java
CODE

package edu.uhcl.sce.palindrome;

import java.util.Stack;

public class ReverseString{
    
    private Stack<Character> st;
    
    public String revString(String s){
        StringBuffer sb = new StringBuffer();
        for(int i=0; i<s.length(); ++i){
            st.push(s.charAt(i));
        }
        while (!st.empty()){
            char c = st.pop();
            sb.append(c);
        }
        return sb.toString();
    }
}


Any help would be appreciated.
Thanks
Robert
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Cannot Find Symbol Constructor Error, But Can't Seem To Find The P
17 Feb, 2008 - 08:58 PM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
It's this part of the code:
ReverseString revString = new ReverseString(sUpper);

You're trying to make a new object of type "ReverseString", but there is no constructor that takes an argument. In fact there isn't a constructor. You should therefore create it like this:
ReverseString revString = new ReverseString();.

Then you want to get your reversed string, do it like this:
CODE

String newString;
newString = revString.revString(sUpper);


Hope that helps.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:04PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month