Android Java에서 클래스를로드 할 수 없습니다.

user134929

안녕하세요 내 안드로이드 앱에서 클래스를로드 할 수 없습니다. 기본 클래스를로드 할 수 있지만 해당 클래스에서 컨텍스트를 초기화하면로드 할 수 없습니다.

public class main {
    // Initalize context
    Context mContext;
    public main(Context mContext){
        this.mContext = mContext;
    }
    public boolean main() {
 Log.d("MYLOG", "main() called successfully when there context is not initialized like above");
// some code here  
}
}

내 클래스 로딩 코드

try{
     final File tmpDir = context.getDir("dex", 0);
     final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader());
     final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("com.myproject.test.dumy_class");   // package plus main class
     final Object myInstance = classToLoad.newInstance();       // throwing exception here 
}
    } catch (Exception e) {
// exception thrown at that statement :   final Object myInstance = classToLoad.newInstance(); 
}

내가 얻은 예외 :

java.lang.InstantiationException : com.myproject.test.dumy_class 클래스를 인스턴스화 할 수 없습니다. 빈 생성자 없음

그래서 제발 도와주세요.

마틴 코네 크니

Java 클래스에 빈 생성자를 만들어야합니다.

public class main {
    // Initalize context
    Context mContext;

    public main(){
    }

    public main(Context mContext){
        this.mContext = mContext;
    }
    public boolean main() {
       Log.d("MYLOG", "main() called successfully when there context is not initialized like above");
        // some code here  
    }
}

이것은 당신이 원하는 것이 아닐 수도있는 빈 생성자 만 호출 할 것입니다.

또는 원하는 생성자를 선택하고 다음과 같이 newInstance 호출에 매개 변수를 추가해야합니다 ( 여기 관련 SO 질문 참조 ).

Class[] cArg = new Class[1];
cArg[0] = Context.class;
classToLoad.getDeclaredConstructor(cArg).newInstance(context);

그래서 비어 있지 않은 생성자

public main(Context mContext)

호출됩니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Android Studio에서 Custom Gradle 플러그인에 대한 클래스를로드 할 수 없습니다.

분류에서Dev

Java가 클래스 경로에서 클래스를로드 할 수 없습니다.

분류에서Dev

Android의 URL에서 클래스를 어떻게로드 할 수 있습니까?

분류에서Dev

Android에서 다른 클래스의 메서드를 호출 할 수 없습니다.

분류에서Dev

'com.android.build.gradle.managed.BuildType_Impl 클래스를로드 할 수 없습니다.

분류에서Dev

C ++의 파생 클래스에서 기본 클래스 메서드를 오버로드 할 수 없습니다.

분류에서Dev

클래스 C ++에서 + 연산자를 오버로드 할 수 없습니다.

분류에서Dev

Spring이 ApplicationContext xml 파일에서 클래스를로드 할 수 없습니다.

분류에서Dev

Bash에서 메인 클래스를 찾거나로드 할 수 없습니다.

분류에서Dev

Java의 클래스에서 void 메서드를 호출 할 수 없습니다.

분류에서Dev

오류 : 기본 클래스 (Java)를 찾거나로드 할 수 없습니다.

분류에서Dev

Java- "기본 클래스를 찾거나로드 할 수 없습니다."

분류에서Dev

JRuby에서 "Java 클래스를로드 할 수 없음"

분류에서Dev

클래스 내부에서 swiftmailer를로드 할 수 없습니다. 오류가 발생합니다. "Swift_SmtpTransport"클래스를 찾을 수 없습니다.

분류에서Dev

java-MAC-오류 : 기본 클래스 (클래스 이름)를 찾거나로드 할 수 없습니다.

분류에서Dev

Webview Android에서 HTML5를로드 할 수 없습니다.

분류에서Dev

Jmockit : net.android.Uri 클래스의 toString 메서드를 모의 할 수 없습니다.

분류에서Dev

Android에서 한 클래스의 메서드를 다른 클래스로 어떻게 호출 할 수 있습니까?

분류에서Dev

메서드 그룹이므로 클래스에 할당 할 수 없습니다.

분류에서Dev

Acceleo. 매개 변수 클래스 중 하나를 메서드에 대해로드 할 수 없습니다.

분류에서Dev

Android ConnectivityManager 클래스에서 isNetworkSupported에 액세스 할 수 없습니다.

분류에서Dev

Android Webview에서 HTML 텍스트를로드 할 수 없습니다.

분류에서Dev

JavaFX 프로젝트에서 클래스 필드를 인스턴스화 할 수 없습니다.

분류에서Dev

Android Studio에서 HTML을 다운로드 할 수 없습니다.

분류에서Dev

Xcode 5.0에서 OCMock 2.1+로 클래스 메서드를 스텁 할 수 없습니다.

분류에서Dev

Java에서 클래스 메소드에 액세스 할 수 없습니다.

분류에서Dev

Linux에서 android-studio를 시작할 수 없습니다.이 오류가 발생합니다. 오류 : 메인 클래스 com.intellij.idea.Main을 찾거나로드 할 수 없습니다.

분류에서Dev

Android가 조각에서 센서 서비스 클래스를 시작할 수 없습니다.

분류에서Dev

'User'클래스에서 'setEmail'메서드를 확인할 수 없습니다.

Related 관련 기사

  1. 1

    Android Studio에서 Custom Gradle 플러그인에 대한 클래스를로드 할 수 없습니다.

  2. 2

    Java가 클래스 경로에서 클래스를로드 할 수 없습니다.

  3. 3

    Android의 URL에서 클래스를 어떻게로드 할 수 있습니까?

  4. 4

    Android에서 다른 클래스의 메서드를 호출 할 수 없습니다.

  5. 5

    'com.android.build.gradle.managed.BuildType_Impl 클래스를로드 할 수 없습니다.

  6. 6

    C ++의 파생 클래스에서 기본 클래스 메서드를 오버로드 할 수 없습니다.

  7. 7

    클래스 C ++에서 + 연산자를 오버로드 할 수 없습니다.

  8. 8

    Spring이 ApplicationContext xml 파일에서 클래스를로드 할 수 없습니다.

  9. 9

    Bash에서 메인 클래스를 찾거나로드 할 수 없습니다.

  10. 10

    Java의 클래스에서 void 메서드를 호출 할 수 없습니다.

  11. 11

    오류 : 기본 클래스 (Java)를 찾거나로드 할 수 없습니다.

  12. 12

    Java- "기본 클래스를 찾거나로드 할 수 없습니다."

  13. 13

    JRuby에서 "Java 클래스를로드 할 수 없음"

  14. 14

    클래스 내부에서 swiftmailer를로드 할 수 없습니다. 오류가 발생합니다. "Swift_SmtpTransport"클래스를 찾을 수 없습니다.

  15. 15

    java-MAC-오류 : 기본 클래스 (클래스 이름)를 찾거나로드 할 수 없습니다.

  16. 16

    Webview Android에서 HTML5를로드 할 수 없습니다.

  17. 17

    Jmockit : net.android.Uri 클래스의 toString 메서드를 모의 할 수 없습니다.

  18. 18

    Android에서 한 클래스의 메서드를 다른 클래스로 어떻게 호출 할 수 있습니까?

  19. 19

    메서드 그룹이므로 클래스에 할당 할 수 없습니다.

  20. 20

    Acceleo. 매개 변수 클래스 중 하나를 메서드에 대해로드 할 수 없습니다.

  21. 21

    Android ConnectivityManager 클래스에서 isNetworkSupported에 액세스 할 수 없습니다.

  22. 22

    Android Webview에서 HTML 텍스트를로드 할 수 없습니다.

  23. 23

    JavaFX 프로젝트에서 클래스 필드를 인스턴스화 할 수 없습니다.

  24. 24

    Android Studio에서 HTML을 다운로드 할 수 없습니다.

  25. 25

    Xcode 5.0에서 OCMock 2.1+로 클래스 메서드를 스텁 할 수 없습니다.

  26. 26

    Java에서 클래스 메소드에 액세스 할 수 없습니다.

  27. 27

    Linux에서 android-studio를 시작할 수 없습니다.이 오류가 발생합니다. 오류 : 메인 클래스 com.intellij.idea.Main을 찾거나로드 할 수 없습니다.

  28. 28

    Android가 조각에서 센서 서비스 클래스를 시작할 수 없습니다.

  29. 29

    'User'클래스에서 'setEmail'메서드를 확인할 수 없습니다.

뜨겁다태그

보관