我使用了以下內容:反射拋出java.lang.ClassNotFoundException
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case EDIT_ADJUSTMENT:
if(resultCode == RESULT_OK){
try{
String adjustment = data.getStringExtra("adjustment");
adjustment = adjustment.replace(" ", "");
ClassLoader myClassLoader = ClassLoader.getSystemClassLoader();
String classNameToBeLoaded = "com.picpic.adjustments." + adjustment;
Class adjust = myClassLoader.loadClass(classNameToBeLoaded);
}catch(Exception e){
String msg = e.getMessage();
}
}
break;
}
}
當它到達Class adjust = myClassLoader.loadClass(classNameToBeLoaded);
我得到以下異常:java.lang.ClassNotFoundException: com.picpic.adjustments.ColorCorrect
的ColorCorrect
包是com.picpic.adjustments
所以,爲什麼這個錯誤被拋出?如果您需要更多信息,請告訴我。謝謝!
如果您直接訪問該類,它是否工作,例如, '類c = com.picpic.adjustments.ColorCorrect.class;' - 你確定類是在類路徑上? – DNA
它與執行onActivityResult的活動是否在相同的apk中? – Snicolas
只是一個猜測,但它可能是錯誤的'ClassLoader'爲您的班級 – zapl