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 7741775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:06:49+00:00 2026-06-01T09:06:49+00:00

I am getting an error from a piece of code. I will only show

  • 0

I am getting an error from a piece of code. I will only show one line of code, at least the line I believe is causing it from the error report. It is:

b = temp(temp.length-1).toInt; //temp is an ArrayBuffer[String]

the error is:

For input string: "z"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at scala.collection.immutable.StringLike$class.toInt(StringLike.scala:231)
at scala.collection.immutable.StringOps.toInt(StringOps.scala:31)
at Driver$.stringParse$1(Driver.scala:59)
at Driver$.main(Driver.scala:86)
at Driver.main(Driver.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:78)
at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:88)
at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:78)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:56)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

From what I can tell, it is causing an issue with this. Since it is immutable, I know it cannot be changed. But I am not sure. I am basing this off of

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

Once I do something like my lone of code above, does it change the whole object? Temp is an ArrayBuffer[String]. So I am trying to access a string representation of a number, and convert it. But in doing so, does this change what it is and keep me from doing anything?

If you believe putting all my code will be helpful, let me know to edit it, but it is a lot and I don’t want to annoy anybody. I appreciate anybody who can help me understand this!

*EDIT: MY CODE (Only here to help me figure out my error, but not necessary to look at. I just can’t see where its giving me this error).

The point of my code is to parse either one of those strings at the top. It puts together and into one string and then reads the other two symbols to go with it. It parses str just fine, but it finds a problem when it reads “z” in str2, and “y” in str3. As one can see, the problem is with the second string after the and when recursing. Its also important to note that the string has to be in that form. So it can only be parsed like “(and x (and y z))”, but not in any other way that makes it more convenient.

val str = "(and x y)";
val str2 = "(and x (and y z))"; //case with expression on th right side
val str3 = "(and (and x y) z)"; //case with expression ont he left side

var i = 0; //just counter used to loop through the finished parsed array to make a list
//var position = 0; //this is used for when passing it in the parser to start off at zero
var hold = new ArrayBuffer[String]();//finished array should be here

def stringParse ( exp: String, expreshHolder: ArrayBuffer[String] ): ArrayBuffer[String] = { //takes two arguments, string, arraybuffer
    var b = 0; //position of where in the expression String I am currently in
    var temp = expreshHolder; //holder of expressions without parens
    var arrayCounter = 0;
    if(temp.length == 0) 
        b = 0; 
        else {
            b = temp(temp.length-1).toInt;
            temp.remove(temp.length-1); 
            arrayCounter = temp.length;
        } //this sets the position of wherever the string was read last plus removes that check from the end of the ArrayBuffer
     //just counts to make sure an empty spot in the array is there to put in the strings

    if(exp(b) == '(') {
        b = b + 1;

        while(exp(b) == ' '){b = b + 1;} //point of this is to just skip any spaces between paren and start of expression type
        if(exp(b) == 'a') {
            //first create the 'and', 'or', 'not' expression types to figure out 
            temp += exp(b).toString;
            b = b+1; 
            temp(arrayCounter) = temp(arrayCounter) + exp(b).toString; //concatenates the second letter
            b = b+1; 
            temp(arrayCounter) = temp(arrayCounter) + exp(b).toString; //concatenates the last letter for the expression type
            //arrayCounter+=1;
            //this part now takes the symbols and puts them in an array
            b+=1;

            while(exp(b) == ' ') {b+=1;} //just skips any spaces until it reaches the FIRST symbol
            if(exp(b) == '(') { 
                temp += b.toString; 
                temp = stringParse(exp, temp); 
                b = temp(temp.length-1).toInt; 
                temp.remove(temp.length-1); 
                arrayCounter = temp.length-1 
                } else {
                    temp += exp(b).toString; 
                    arrayCounter+=1; b+=1; }

            while(exp(b) == ' ') {b+=1;} //just skips any spaces until it reaches the SECOND symbol
            if(exp(b) == '(') { 
                temp += b.toString;
                temp = stringParse(exp, temp); 
                b = temp(temp.length-1).toInt; 
                temp.remove(temp.length-1); 
                arrayCounter = temp.length-1 
                } else {
                    temp += exp(b).toString; 
                    arrayCounter+=1; 
                    b+=1; 

        } 
    temp;
    } else { var fail = new ArrayBuffer[String]; fail +="failed"; fail;}

}
hold = stringParse(str2, ho );
for(test <- hold) println(test);
  • 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-06-01T09:06:52+00:00Added an answer on June 1, 2026 at 9:06 am

    What does temp contain? Your code assumes that it contains Strings that can be converted to Ints, but it seems that you have a String "z" in there instead. That would produce the error:

    scala> "z".toInt
    java.lang.NumberFormatException: For input string: "z"
    ...
    

    Here’s a recreation of what temp might look like:

    val temp = ArrayBuffer("1", "2", "z")
    temp(temp.length-1).toInt //java.lang.NumberFormatException: For input string: "z"
    

    So you need to figure out why some String "z" is getting into temp.

    EDIT:

    So you’re adding “expressions” to temp (temp += exp(b).toString) and also adding indices (temp += b.toString). Then you’re assuming that temp only holds indices (b = temp(temp.length-1).toInt). You need to decide what temp is for, and then use it exclusively for that purpose.

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

Sidebar

Related Questions

Here is the piece of code that I am getting error, SDL_Rect's definition is
I am getting a strange error message with the following piece of PHP code
Why am I getting an error for this piece of code?: function catchevent() {
From the below piece of code, why I am getting Reading Socket for response
I'm getting reports from my website of weird Javascript errors in a piece of
I'm getting an Error from Debugger: Error launching remote program: security policy error when
What are the most common reasons that I would be getting this error from
I'm getting an error message from a python script at position 21490 . How
I am getting a compile error from the following property. The error is: The
I am getting the folloinwg error from NHibernate: System.ObjectDisposedException: Session is closed! Object name:

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.