java - "Length must be at least 1 (was -1)" what causes this and how do I fix it? -


i error line of code:

enter image description here

this getbackground() looks like:

public class myclass {    ...    private string background;    public string getbackground() {     return background;   }    ... } 

i've verified color.parsecolor takes string. why happening, , how can make compiler happy?

this doesn't stop app running, perhaps static analyzer thing? tried putting return value getbackground() in local , checking non-null , had length() >= 1, didn't appear solve anything.

looks pretty issue 1 of static analyzer inspections. if pass string literal color#parsecolor(string), e.g. color.parsecolor("#eee"); issue disappears.
looks static analyzer isn't smart enough infer value pass in (which return value of getbackground()) non-null in possible cases, shows possibly value null or empty. if you're sure color string non-null can suppress so:

//noinspection resourcetype view.setcolor(color.parsecolor(model.getcolor().getbackground())); 

Comments