较低版本的android

时间:2016-05-14 09:59:52

标签: android android-studio android-gradle noclassdeffounderror

我在android os 4.3 API 18中运行应用程序时出现此错误,但如果它在os 5.1.0 API 22上正常工作

    java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:289)
at android.view.View.performClick(View.java:4240)
at android.view.View$PerformClick.run(View.java:17721)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4240) 
at android.view.View$PerformClick.run(View.java:17721) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.TypeNotPresentException: Type com.webakruti.soilreport.model.LoginResponse not present
at org.apache.harmony.luni.lang.reflect.ImplForType.getRawType(ImplForType.java:64)
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:73)
at org.apache.harmony.luni.lang.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:61)
at org.apache.harmony.luni.lang.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:53)
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:72)
at org.apache.harmony.luni.lang.reflect.Types.getType(Types.java:29)
at java.lang.Class.getGenericSuperclass(Class.java:761)
at com.google.gson.reflect.TypeToken.getSuperclassTypeParameter(TypeToken.java:82)
at com.google.gson.reflect.TypeToken.
<init>
(TypeToken.java:62)
at com.webakruti.soilreport.ui.activities.LoginActivity$2.
<init>
(LoginActivity.java:79)
at com.webakruti.soilreport.ui.activities.LoginActivity.login(LoginActivity.java:79)
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 
at android.view.View.performClick(View.java:4240) 
at android.view.View$PerformClick.run(View.java:17721) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.ClassNotFoundException: com.webakruti.soilreport.model.LoginResponse
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at org.apache.harmony.luni.lang.reflect.ImplForType.getRawType(ImplForType.java:62)
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:73) 
at org.apache.harmony.luni.lang.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:61) 
at org.apache.harmony.luni.lang.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:53) 
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:72) 
at org.apache.harmony.luni.lang.reflect.Types.getType(Types.java:29) 
at java.lang.Class.getGenericSuperclass(Class.java:761) 
at com.google.gson.reflect.TypeToken.getSuperclassTypeParameter(TypeToken.java:82) 
at com.google.gson.reflect.TypeToken.
<init>
(TypeToken.java:62) 
at com.webakruti.soilreport.ui.activities.LoginActivity$2.
<init>
(LoginActivity.java:79) 
at com.webakruti.soilreport.ui.activities.LoginActivity.login(LoginActivity.java:79) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 
at android.view.View.performClick(View.java:4240) 
at android.view.View$PerformClick.run(View.java:17721) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NoClassDefFoundError: com/webakruti/soilreport/model/LoginResponse
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:204) 
at org.apache.harmony.luni.lang.reflect.ImplForType.getRawType(ImplForType.java:62) 
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:73) 
at org.apache.harmony.luni.lang.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:61) 
at org.apache.harmony.luni.lang.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:53) 
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:72) 
at org.apache.harmony.luni.lang.reflect.Types.getType(Types.java:29) 
at java.lang.Class.getGenericSuperclass(Class.java:761) 
at com.google.gson.reflect.TypeToken.getSuperclassTypeParameter(TypeToken.java:82) 
at com.google.gson.reflect.TypeToken.
<init>
(TypeToken.java:62) 
at com.webakruti.soilreport.ui.activities.LoginActivity$2.
<init>
(LoginActivity.java:79) 
at com.webakruti.soilreport.ui.activities.LoginActivity.login(LoginActivity.java:79) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 
at android.view.View.performClick(View.java:4240) 
at android.view.View$PerformClick.run(View.java:17721) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.webakruti.soilreport.model.LoginResponse" on path: DexPathList[[zip file "/data/app/com.webakruti.soilreport-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.webakruti.soilreport-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:204) 
at org.apache.harmony.luni.lang.reflect.ImplForType.getRawType(ImplForType.java:62) 
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:73) 
at org.apache.harmony.luni.lang.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:61) 
at org.apache.harmony.luni.lang.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:53) 
at org.apache.harmony.luni.lang.reflect.ImplForType.getResolvedType(ImplForType.java:72) 
at org.apache.harmony.luni.lang.reflect.Types.getType(Types.java:29) 
at java.lang.Class.getGenericSuperclass(Class.java:761) 
at com.google.gson.reflect.TypeToken.getSuperclassTypeParameter(TypeToken.java:82) 
at com.google.gson.reflect.TypeToken.
<init>
(TypeToken.java:62) 
at com.webakruti.soilreport.ui.activities.LoginActivity$2.
<init>
(LoginActivity.java:79) 
at com.webakruti.soilreport.ui.activities.LoginActivity.login(LoginActivity.java:79) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 
at android.view.View.performClick(View.java:4240) 
at android.view.View$PerformClick.run(View.java:17721) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method)

java代码

   public void login(View v) {
    email = edtLogin.getText().toString();
    pwd = edtPassword.getText().toString();

    postParam = new HashMap<String, String>();
    postParam.put("username", email);
    postParam.put("password", pwd);
    postParam.put("grant_type", "password");

    JSONObject object = new JSONObject(postParam);
    Type type = new TypeToken<LoginResponse>() {
   }.getType();
    // GeneralRequest.login(LoginActivity.this, type, object, LoginActivity.this, LoginActivity.this);
    callApi(postParam);
}

XML where the method is called:
 <Button
    android:id="@+id/login"
    android:layout_width="@dimen/width_400"
    android:layout_height="wrap_content"
    android:background="@drawable/btn_background"
    android:layout_below="@+id/password"
    android:layout_centerHorizontal="true"
    android:onClick="login"
    android:text="Login"
    android:textStyle="bold"
    android:textAllCaps="false"
    android:layout_marginTop="@dimen/margin_corner"
    android:textColor="@android:color/white"
    />

GRADLE APP文件 -

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc2"

defaultConfig {
    applicationId "com.mycompany.soilreport"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),      'proguard-rules.pro'
    }
}

dexOptions {
    incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g" // 2g should be also OK
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.code-troopers.betterpickers:library:2.5.3'
compile files('libs/itextg-5.5.4.jar')
}

到目前为止我尝试过的事情:

  1. 重启android studio
  2. 重新启动geny motion
  3. 重新启动我的笔记本电脑。
  4. 再次克隆项目
  5. 检查了java版本和gradle版本
  6. 卸载了apk并重新安装
  7. 检查所有变量的初始化
  8. 任何人都可以解释为什么我的构建文件有问题吗?

1 个答案:

答案 0 :(得分:0)

public class MainActivity extends Activity { 

public void login(View v) {
email = edtLogin.getText().toString();
pwd = edtPassword.getText().toString();

postParam = new HashMap<String, String>();
postParam.put("username", email);
postParam.put("password", pwd);
postParam.put("grant_type", "password");

JSONObject object = new JSONObject(postParam);
Type type = new TypeToken<LoginResponse>() {
}.getType();
// GeneralRequest.login(LoginActivity.this, type, object,  LoginActivity.this, LoginActivity.this);
callApi(postParam);
}

//activity oncreated method and other override methods

}

这里注意到我告诉你的一件事,你应该将你的onclick方法放在你的活动中但是在&#34; @ override&#34;之外。方法因为那些是活动生成的方法。