java.lang.NoClassDefFoundError: Could not initialize class XXX

后端 未结 10 1229
無奈伤痛
無奈伤痛 2020-11-27 10:59
public class PropHolder {
  public static Properties prop;

  static {
    //code for loading properties from file
  }
}

// Referencing the class somewhere else:
Pr         


        
10条回答
  •  佛祖请我去吃肉
    2020-11-27 11:29

    If you're working on an Android project, make sure you aren't calling any static methods on any Android classes. I'm only using JUnit + Mockito, so maybe some other frameworks might help you avoid the problem altogether, I'm not sure.

    My problem was calling Uri.parse(uriString) as part of a static initializer for a unit test. The Uri class is an Android API, which is why the unit test build couldn't find it. I changed this value to null instead and everything went back to normal.

提交回复
热议问题