1
votes

From the Kotlin docs

object Obj {
    const val CONST = 1
}

Should be enough for accessing from Java as Obj.CONST

But with similar it got error.

object StringUtils {
    const val UNESCAPE_HTML4 = "... ..."
    ......
}

In Java code

return StringUtils.UNESCAPE_HTML4;

Got error

'UNESCAPE_HTML4' has private access in com.data.utils.StringUtils

Has to use StringUtils.INSTANCE.getUNESCAPE_HTML4() then no error.

Clicking on that UNESCAPE_HTML4 does opens the compiled code correctly though.

The only difference is this object StringUtils is from a libray dependency which has been added to the project's build.gradle

Anyone also seeing this type error?

Here is a test function in the Java side, which tries to access those function, property from the dependent library.

public class DataWrapper {
    ... ...
    public void test_strUtil() {

    /*
     * For example, the string "<Français>"
     * will become "<Franais>"
     */

    String s = StringUtils.unescapeHtml4("<Français>");



    int s2 = Constants.CONTROLLER_FANTASY_SPORTS_STREAM;

    String[][] arr = EntityArrays.BASIC_UNESCAPE();

    Log.i("+++", "+++ test_strUtil(), after DataPlay.init(), unescapeHtml4:"+s+", empty:"
          +StringUtils.EMPTY+" --- s2:"+s2);

    for (int i=0; i<arr.length; i++) {
        String[] arrRow = arr[i];
        for (int j=0; j< arrRow.length; j++) {
            Log.w("+++", "+++ arrRow["+i+"]["+j+"]:"+arrRow[j]);
        }
    }
}

The IDE shows red on them and says "non static method...",

enter image description here

Or "has private access..."

enter image description here

But when clicking on the complained function or property, it does opens the correct compiled file

enter image description here

And

enter image description here

And when it runs, the print out shows the function called correctly.

com.test.debug I/+++: +++ test_strUtil(), after DataPlay.init(), 
               unescapeHtml4:&lt;Fran&ccedil;ais&gt;, empty: --- s2:3
com.test.debug W/+++: +++ arrRow[0][0]:&quot;
    +++ arrRow[0][1]:"
    +++ arrRow[1][0]:&amp;
    +++ arrRow[1][1]:&
    +++ arrRow[2][0]:&lt;
    +++ arrRow[2][1]:<
    +++ arrRow[3][0]:&gt;
    +++ arrRow[3][1]:>

And more weird is from same library the other function and property exposed through different object class's const or @JvmStatic they don't get complain by the IDE.

1
Tried to reproduce your issue, but everything seems to work fine. How do you build this "library" of yours?Alexey Soshin
@Alexey, the library is from another library project, published to maven and added dependency on it in this projectlannyf
Can you rebuild this library? Since it should work, my assumption is that it was build by an old Kotlin compiler, around 1.0Alexey Soshin
I rebuild both constantly, my AndroidStudio is 3.1.3, and kotlin is 1.2.60lannyf
Ok, so you forgot to mention that the problem is not with the code, but only with the IDE. Stupid question, but did you try to clean the project? IntelliJ keeps internal caches of things.Alexey Soshin

1 Answers

1
votes

There are a few points here:

  1. The error appears only in IDE, not during compilation
  2. Happens only when the class is in a library (I tried to reproduce the problem with class in same project, it works as expected)

If clean/rebuild doesn't help, deleting the entire project and importing it again should.