javaxml

IBM Host On Demand Macro (HAScript) - Getting error msg "Class java.util.Scanner does not contain the specified method hasNextInt"


I'm new to IBM Host On Demand Macro (HAScript). It uses an XML format, but you can import Java classes and call methods. I would like to to read a list of integers into a variable and iterate through them, performing actions on each. In the code below I'm just attempting to read integers from a text file using java.util.scanner, my first step before attempting to loop.

I'm getting error msg "Macro.PlayThread.playActions(MacroActions,MacroScreen): Class java.util.Scanner does not contain the specified method hasNextInt".

I'm trying to utilize the manuals, but they are vague to say the least and it's been hard to find examples. Any help would be greatly appreciated. My background is in SQL, not Java or XML. Thanks!

My Code:

<import>
    <!-- Importing Necessary Java classes -->
    <type class="java.io.File" name="javaFile"/>
    <type class="java.io.FileReader"/>
    <type class="java.io.BufferedReader"/>
    <type class="java.io.IOException"/>
    <type class="java.util.ArrayList"/>
    <type class="java.util.Scanner" name="javaScanner"/>
</import>

<vars>
  <!-- Creating an ArrayList variable named $list$ -->
  <create name="$list$" type="java.util.ArrayList" value="$new java.util.ArrayList()$" />
</vars>


<screen name="Screen1" entryscreen="true" exitscreen="true" transient="false">
    <description >
        <!-- OIA settings -->
        <oia status="NOTINHIBITED" optional="false" invertmatch="false" />
    </description>
    <actions>
        <!-- Read integers from the text file -->
        <perform value="$new javaFile(&apos;C:\\Users\\Documents\\scripts\\apps\\allow\\acctlist.txt&apos;)$"  />
        <perform value="$new javaScanner(&apos;C:\\Users\\Documents\\scripts\\apps\\allow\\acctlist.txt&apos;)$"  />
        <if condition="$javaScanner.hasNextInt(true)$" >
              <perform value="$javaScanner.nextInt()$"  />
        </if>
        <else>
              <perform value="$javaScanner.close()$"  />
        </else>
        <!-- Displaying $list$ content (for debugging, remove later) -->
        <message title="" value="$javaScanner.toString()$" />
    </actions>
    <nextscreens timeout="0" >
    </nextscreens>
</screen>

Solution

  • Thanks to John Pimentel's collaboration, I am posting a script below that will read integers from a text file into a variable and loop through them. I was able to use this to create a HAScript macro that performs actions on a list of accounts.

    <import>
        <type class="java.io.File" name="javaFile"/>
        <type class="java.util.Scanner" name="javaScanner"/>
    </import>
    
    <vars>
      <create name="$fileName$" type="javaFile" value="$new javaFile('C:\\Users\\MyName\\Documents\\share1A.txt')$" />
      <create name="$lineScanner$" type="javaScanner" value="$new javaScanner($fileName$)$" />
      <create name="$lineScanner1$" type="string" value="$lineScanner.hasNextLine()$" />
      <create name="$myString$" type="string" value="$lineScanner.next()$" />
    </vars>
    
    
    <screen name="Screen1" entryscreen="true" exitscreen="false" transient="false">
        <description >
            <oia status="NOTINHIBITED" optional="false" invertmatch="false" />
        </description>
        <actions>
            <message title="&apos;RESULTS1&apos;" value="&apos;A1: &apos;+$myString$" />
        </actions>
        <nextscreens timeout="0" >
            <nextscreen name="Screen2" />
        </nextscreens>
        <recolimit value="10000" />
    </screen>
    
    <screen name="Screen2" entryscreen="true" exitscreen="false" transient="false">
        <description >
            <oia status="NOTINHIBITED" optional="false" invertmatch="false" />
       
        </description>
        <actions>
            <varupdate name="$myString$" value="$lineScanner.next()$" />
        </actions>
        <nextscreens timeout="0" >
            <nextscreen name="Screen1" />
        </nextscreens>
    </screen>