TransWikia.com

Incorrect number or type of arguments when using @contains[ ]

Mathematica Asked by Mara Luisa Amada Tercero on December 12, 2020

I tried to make the old code you suggested me a little faster by doing this changes:

Needs["JLink`"]

Scanner[archivo_String, palabra_String] :=
 JavaBlock@
  Module[{entrada, linea, numlinea, contiene, ruta}, numlinea = 1; 
   linea = ""; contiene = False;
   InstallJava[];
   ruta = JavaNew["java.io.File", archivo];
   entrada = JavaNew["java.util.Scanner", ruta];
   Print["Archivo: " <> ruta@getName[]];
   Print["Texto a buscar:" <> palabra];
   While[entrada@hasNext[], linea = entrada@nextLine[]; 
    If[JavaNew["java.lang.String", linea]@contains[palabra], 
     Print["Linea:" <> numlinea <> ":" <> linea];
     contiene = True]; numlinea++]; 
   If[! contiene, Print[ palabra <> " no se ha encontrado"]]]

But I get this and don’t know why. It’s not working cause "issue" appears several times.

enter image description here

Hope you can help me

One Answer

The contains method requires a java.lang.String (or some other implementation of the CharSequence interface), not a Wolfram Language expression. Try using contains[MakeJavaObject@palabra] instead of contains[palabra]. There are more messages after that is fixed, I haven't looked at those.

Correct answer by Jason B. on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP