I imported my project from Eclipse to Android Stdio and it works on Lollipop devices, if I run on kitkat devices it gives me the exception "No class def found".
In my project, I have two packages 1. com.qapp , which has the main functionality class and 2. om.qapp.common_class , which usually used the functionality class, for example, I have UtillClass , there is a method called showOkAlert , which is used to display a warning dialog with the ok button.
If I called the showOkAlert methods from Activity, it successfully executed on all Lollipop devices and other version devices,
java.lang.NoClassDefFoundError .
Code example:
package com.qapp.common_class;
public class UtillClass {
public static void showOkAlert(final Context context, final String msgBody) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setTitle(context.getResources().getString(
R.string.alert_msg_title));
alertDialogBuilder.setMessage(msgBody).setCancelable(false)
.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
And I used the showOkAlert method in Activity as follows:
package com.qapp;
import com.qapp.common_class.UtillClass;
public class TestActivity2 extends Activity {
private Button sendPush, gotoQnow;
.............
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.gonow);
gotoQnow = (Button) findViewById(R.id.gotonow_btn);
.............
gotoQnow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
UtillClass.showOkAlert(TestActivity2.this,"hello");
}
});
}
}
Note:
- Their work on Eclipse, without exception, on all types of Android version.
- In Android studio (an imported project) it works only on Lollipop devices, on another device with a version of
NoClassDefFoundError .
- I clean the assembly and rebuild so many times, but don't use it.
- It is very strange to understand what happens between 5.0 and other devices during operation.
- I am using android studio 1.4.1
- The minimum version of the SDK is 14
, Android, Android, , . , , .
My Log here:
java.lang.NoClassDefFoundError: com.qapp.common_class.UtillClass$1
at com.qapp.common_class.UtillClass.showOkAlert(UtillClass.java:382)
at com.qapp.TestActivity2$1.onClick(TestActivity2.java:53)
at android.view.View.performClick(View.java:3528)
at android.view.View$PerformClick.run(View.java:14235)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NoClassDefFoundError: com.qapp.common_class.UtillClass$1
at com.qapp.common_class.UtillClass.showOkAlert(UtillClass.java:382)
at com.qapp.TestActivity2$1.onClick(TestActivity2.java:53)
at android.view.View.performClick(View.java:3528)
at android.view.View$PerformClick.run(View.java:14235)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
Utillclass
import java.io.FileNotFoundException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.TimeZone;
import org.json.JSONArray;
import org.json.JSONObject;
import retrofit.RetrofitError;
import retrofit.client.Response;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader.TileMode;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.util.Base64;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;