1

I have a method which takes : "java.io.Reader" as argument java.io.Reader is an Interface and cannot be instancied.

So, I use one sub class like this: StringReader= jp.java.io.StringReader("teststring")

How can I convert StringReader into java.io.Reader type ?

Because the method cannot do implicetely.

EDIT: I receive this error message when using the method:

   txt= u'gfdgfdgddf'
   StringReader = jp.JClass('java.io.StringReader')(txt)
   StringReader.ready()  #Ok works
   userDicC= jp.JClass('org.apache.lucene.analysis.ja.dict.UserDictionary')
   useDic= userDicC(StringReader)

Method details: public static UserDictionary open(Reader reader) throws IOException

I got this error:

userDicC= java.jp.JClass('org.apache.lucene.analysis.ja.dict.UserDictionary') useDic= userDicC(StringReader)

    line 84, in _javaInit
    self.__javaobject__ = self.__class__.__javaclass__.newClassInstance(*args)

   RuntimeError: No matching overloads found. at  src\native\common\jp_method.cpp:121
7
  • Why do you think you need to cast the object? What happens if you pass the StringReader to the method you say needs a java.io.Reader? Commented Mar 27, 2016 at 12:09
  • Because I received a error message: Commented Mar 27, 2016 at 12:26
  • And what was that error message? Please edit your question to include this message. Commented Mar 27, 2016 at 12:35
  • What method are you calling? What parameter types does it take and what values are you passing for any other parameters? The reason I ask this is that I tried creating a BufferedReader from a StringReader and that worked. Commented Mar 27, 2016 at 12:45
  • I put the apache method in the code. Commented Mar 27, 2016 at 12:58

1 Answer 1

1

From the comments it turns out that the problem is not related to casting an object at all.

To call the method public static UserDictionary open(Reader reader), you need to replace the line

useDic= userDicC(StringReader)

with

useDic= userDicC.open(StringReader)

The former line will not work because in version 5.5.0 of Lucene-Kuromoji the UserDictionary class declares no public constructors. (The class does have a private constructor that takes a List<String[]> parameter and the static open method calls this.)

Confusingly, older versions of this class, such as that in version 5.0.0 of Lucene-Kuromoji, do declare a constructor that takes a single Reader parameter. I would expect your code to have worked with that version of Lucene-Kuromoji.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.