Android 4.4中运行启动时应用程序崩溃(NoClassDefFoundError)

时间:2016-08-13 11:18:02

标签: android android-fragments android-fragmentactivity dalvik

在Android 4.4中运行并显示NoClassDefFoundError时,应用程序崩溃。但在其他Android版本6.0正常工作。我在这里使用片段活动。错误如下所示。

  public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            LoginPatternFragment loginFragement = new LoginPatternFragment();
            fragmentTransaction.add(R.id.fragement, loginFragement);
            fragmentTransaction.commit();
        }
    }

ERROR:

 E/memtrack: Couldn't load memtrack module (No such file or directory)
    E/android.os.Debug: failed to load memtrack module: -2
    E/dalvikvm: Could not find class 'com.quicknip.restaurant3.Fragment.LoginPatternFragment$13', referenced from method com.quicknip.restaurant3.Fragment.LoginPatternFragment.loginService
    E/dalvikvm: Could not find class 'com.quicknip.restaurant3.Fragment.LoginPatternFragment$1', referenced from method com.quicknip.restaurant3.Fragment.LoginPatternFragment.onCreateView
    E/GMPM: Task exception on worker thread: java.lang.NoClassDefFoundError: com.google.android.gms.R$string: com.google.android.gms.measurement.zza.<init>(Unknown Source)
    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.quicknip.restaurant3, PID: 2733
    java.lang.NoClassDefFoundError: com.quicknip.restaurant3.Fragment.LoginPatternFragment$1
    at com.quicknip.restaurant3.Fragment.LoginPatternFragment.onCreateView(LoginPatternFragment.java:59)

1 个答案:

答案 0 :(得分:1)

创建一个这样的类

class MyApplication extends Application {

@Override
protected void attachBaseContext(Context base) {
  super.attachBaseContext(base);
  MultiDex.install(this);
}
}

在AndroidManifest中,为您的应用标记添加name属性:

<application name=".MyApplication"