Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:13:34+00:00 2026-05-25T18:13:34+00:00

I am trying to add the chars from a string in a textbox into

  • 0

I am trying to add the chars from a string in a textbox into my Stack,

here is my code so far:

String s = txtString.getText();
Stack myStack = new LinkedStack();

  for (int i = 1; i <= s.length(); i++)
{
    while(i<=s.length())
        {
         char c = s.charAt(i);
        myStack.push(c); 
        }
       System.out.print("The stack is:\n"+ myStack);
}

My push and pop method from LinkedStack

public void push(Object item){
  top = new ListNode(item, top); 
}

public void pop(){
  if(isEmpty())
    throw new StackUnderflowException("Nothing removed-stack is empty");
  else
   top = top.getNext();
}

getnext() method comes from another package called listnodes

public ListNode getNext() {
    return nextNode; // get next node
} // end method getNext

when I change the print to + c, all the chars from my string prints, but when it is myStack it now gives me a string out of index range error.

Does anybody know what I am missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:13:35+00:00Added an answer on May 25, 2026 at 6:13 pm

    LinkedStack.toString is not terminating. You’re probably missing a base case there. Add a proper base case to it, and/or make sure your stack doesn’t end up cyclic due to a bug in push or pop, and your print should work fine.

    Your push implementation looks ok, pop doesn’t assign top, so is definitely broken.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to add an element to a database and then return a new
I'm trying to learn ADO.NET from Programmers Heaven: C# School Thats the code I've
I am trying to get a value from with in an ArrayList. Here is
I'm trying to add embedded python to a OpenGL/SDL application. So far everything works
I'm trying to convert a string of characters into each characters decimal form and
I am trying to remove spaces from the end of a char array (string).
I'm basically trying to create a linked list from a text file and add
I am trying to replace a string from an original text. ( zinc -->
Following on from a previous question I had here : Copying a string from
I am trying to remove elements from a Dictionary<string, List<string>> in C# when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.