android studio requestwindowfeature,Android studio:java.lang.NoClassDefFoundError

我已将我的项目从Eclipse导入到Android Stdio,并且它在Lollipop设备上运行,如果我在kitkat设备上运行,它会给我“No class def found”异常.

在我的项目中,我有两个包1. com.qapp,它有核心功能类和2. om.qapp.common_class,它有常用的功能类,例如我有UtillClass,有一个名为showOkAlert的方法,它用于显示带有“确定”按钮的警告对话框.

如果我从一个Activity调用了showOkAlert方法,它在所有Lollipop设备和其他版本设备中成功执行了

java.lang.NoClassDefFoundError.

代码示例:

package com.qapp.common_class;

public class UtillClass {

// static method

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();

}

}

我在Activity中使用了showOkAlert方法,如下所示:

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"); // I get NoClassDefFoundError here Line no #53

}

});

}

}

注意:

>它适用于Eclipse,在所有类型的Android中都没有例外

版.

>在Android工作室(项目导入)仅适用于Lollipop设备,其他版本设备与其坠毁

NoClassDefFoundError错误.

>我已经清理了构建并重建了很多次但没有用.

>了解5.0和其他设备在运行时发生的情况非常奇怪.

>我使用的是Android Studio 1.4.1版

>给出的最低SDK版本为14

请帮我解决这个在Android工作室中的所有Android版本,我花了一天多的时间,但我找不到解决方案.如果您需要更多信息,请在此处发表评论.

我的日志:

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;

解决方法:

我在Android studio中找到了NoClassDefFoundException的解决方案.我在我的Manifest XML中添加了这个

android:name="android.support.multidex.MultiDexApplication"

............

在defaultConfig中添加multiDexEnabled true

defaultConfig {

.......

multiDexEnabled true

}

它现在正在工作,我的源代码没有任何改变.谢谢大家.

标签:android,eclipse,android-studio,noclassdeffounderror

来源: https://codeday.me/bug/20190623/1271355.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值