0

I have a recipe, a list of Strings and int, which they are been recognized from an image.

 String elementText = "";
for (Text.Element element : line.getElements()) {
                        elementText = element.getText();
                        Point[] elementCornerPoints = element.getCornerPoints();
                        Rect elementFrame = element.getBoundingBox();
                        checkObject(elementText);

But, when i do Log.d, i get only strings:

private void checkObject(Object obj) {
        if(obj instanceof Integer){
            Log.d("log int", String.valueOf(obj));
            Log.d("log int", "it's a number");
        }
        else if(obj instanceof String){
            Log.d("log string", (String)obj);
            Log.d("log string", "it's a string");

    }
}

10:21:40.532 D oil
10:21:40.532 D it's a string

10:21:40.534 D garlic
10:21:40.534 D it's a string

10:21:40.537 D oregan
10:21:40.537 D it's a string

10:21:40.545 D 50
10:21:40.545 D it's a string

10:21:40.545 D g
10:21:40.545 D it's a string

10:21:40.545 D 120
10:21:40.545 D it's a string

I was looking to separate them in 1 arraylist with 2 parameters, (string, int). Do you think i need to create an arraylist instead of declaring elementText as string?

enter image description here

Update I also tried this, first part of code works great check() with output: 22:25:56.675 D List [1, 2, 120, 50] function IsInt_ByRegex is still giving int as string:

private void check(String elementText){
    try{
        int num = Integer.parseInt(this.elementText);
        // is an integer!
        Log.d("LOG int", "int " + num);
        list.add(num);
        Log.d("LOG int", "List " + list); //List [1, 2, 120, 50]
    } catch (NumberFormatException e) {
        // not an integer!
    }
}
private void IsInt_ByRegex(String elementText) {

    try{
        elementText.matches("/\\{[a-zA-Z]+\\}/");
        Log.d("LOG string", "string " + elementText);
    }catch (Exception e){

    }
}

Output: 22:25:56.674 D string 50
22:25:56.649 D string red
22:25:56.649 D string peppers
22:25:56.654 D string 120

3
  • element.getText() will always return a String so u can not check type . You need to check the value . See the link above .. Commented Oct 12, 2022 at 14:07
  • Thanks. How can i check the value? i did i little dig into your link, and i try the matches method, but i still get String... see question updated. Commented Oct 12, 2022 at 20:28
  • 22:25:56.675 is not a Integer its an String .. What are you trying to do exactly ? I suggest you should edit your question with proper details .. Some inputs and expected output .. Then only anyone can suggest something .. Right its not very clear .. Commented Oct 15, 2022 at 5:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.