1

I have a StringBuilder argument passed to another module's class method and do some modification, include deleteCharAt, clear, append..., etc.

I got following warning message in Android Studio though the code seems run very well.

Cannot access java.lang.AbstractStringBuilder",

A simple simulation as bellow:

1 - Create an new project with an empty Activity.

2 - Add a Java library module.

3 - library code as bellow:

public class MyClass {

    public void add1(StringBuilder sb){
        sb.append("a");
    }

    public void add2(StringBuffer sb){
        sb.append("b");
    }
}

4 - activity code as bellow:

MyClass mc=new MyClass();
StringBuilder sb1=new StringBuilder();
mc.add1(sb1); // warning: cannot access java.lang.AbstractStringBuilder android
Log.d("SB1",sb1.toString());

StringBuffer sb2=new StringBuffer();
mc.add2(sb2); // warning: cannot access java.lang.AbstractStringBuilder android
Log.d("SB2",sb2.toString());

Android is not a client/server type program, I think it should not be an issue of JRE version problem?

I have run "Inspect Code" but didn't find any further information. Any ideas?

guipivoto
  • 18,327
  • 9
  • 60
  • 75
Renkuei
  • 276
  • 3
  • 8
  • You need to understand difference between them. check [here](https://stackoverflow.com/a/2971343/7783718). – Abhay Koradiya Nov 05 '18 at 12:00
  • @AbhayKoradiya, this is common sense, you should do the simple simulation to see what happens. – Renkuei Nov 05 '18 at 13:55
  • @AbhayKoradiya, still thanks. – Renkuei Nov 05 '18 at 14:45
  • I have a similar issue. I notice it only seems to happen on one of particular call to the method in question, which is in a file which has other 'Lint'-type "errors". Other calls it's perfectly happy with. – Mark Minto Nov 14 '18 at 11:57

0 Answers0