应用程序工作,然后在物理设备(找不到类)和模拟器(无法启动活动组件信息{})上突然崩溃



我的应用程序运行良好,然后在一些更改后,它在我的手机和模拟器上都崩溃了。在手机上启动时,我得到

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.symptoma.android/com.symptoma.android.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.symptoma.android.LoginActivity" on path: DexPathList[[zip file "/data/app/com.symptoma.android-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

在模拟器上

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.symptoma.android/com.symptoma.android.LoginActivity}: android.view.InflateException: Binary XML file line #30: Binary XML file line #30: Error inflating class android.widget.EditText

清单.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.symptoma.android">
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <activity android:name="com.symptoma.android.LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.symptoma.android.SearchActivity" />
        <activity android:name="com.symptoma.android.DisplayResultsActivity" />
    </application>
</manifest>

activity_login.xml

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.NoActionBar">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="56dp"
        android:paddingLeft="24dp"
        android:paddingRight="24dp">
        <ImageView android:src="@drawable/logo"
            android:layout_width="wrap_content"
            android:layout_height="72dp"
            android:layout_marginBottom="24dp"
            android:layout_gravity="center_horizontal"
            android:contentDescription="@string/logo_title" />
        <!-- Email Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="@string/email_hint" />
        </android.support.design.widget.TextInputLayout>
        <!-- Password Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="@string/pass_hint"/>
        </android.support.design.widget.TextInputLayout>
        <android.support.v7.widget.AppCompatButton
            android:id="@+id/btn_login"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:layout_marginBottom="24dp"
            android:padding="12dp"
            android:background="@color/colorPrimary"
            android:textColor="@color/white"
            android:shadowColor="@color/iron"
            android:text="@string/login_button_label"/>
        <TextView android:id="@+id/link_signup"
            android:textColor="@color/colorAccent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="24dp"
            android:text="@string/create_account"
            android:gravity="center"
            android:textSize="16sp"/>
    </LinearLayout>
</ScrollView>

.app

   apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.symptoma.android"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
}
repositories {
    maven {
        url "https://jitpack.io"
        }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-annotations:23.4.0'
    compile files('libs/commons-codec-1.10.jar')
    compile files('libs/commons-io-2.5.jar')
    compile 'org.immutables:gson:2.2'
    compile 'com.jakewharton:butterknife:8.0.1'
    compile 'com.github.coyarzun89:fabtransitionactivity:0.2.0'
    compile 'com.jaredrummler:material-spinner:1.0.9'
    compile 'jp.wasabeef:recyclerview-animators:2.0.0'
    //compile 'com.github.dexafree:materiallist:3.2.+'
    //Core card library
    compile 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0'
    //Optional for built-in cards
    compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
}

登录活动

    package com.symptoma.android;
import com.symptoma.android.R;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LoginActivity extends Activity implements LoginAsyncResponse {
    EditText emailText;
    EditText pwd;
    TextView registerLink;
    LoginTask task = new LoginTask();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        emailText = (EditText) findViewById(R.id.input_email);
        pwd = (EditText) findViewById(R.id.input_password);
        registerLink = (TextView) findViewById(R.id.link_signup);
        registerLink.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://staging.symptoma.com/en/register"));
                startActivity(browserIntent);
            }
        });
        task.delegate = this;
        Button loginButton = (Button) findViewById(R.id.btn_login);
        assert loginButton != null;
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("email", emailText.getText().toString());
                Log.d("pass", pwd.getText().toString());
                if (Utility.isNotNull(emailText.getText().toString()) && Utility.isNotNull(pwd.getText().toString())) {
                    // When Email entered is Valid
                    if (Utility.validate(emailText.getText().toString())) {
                        final ProgressDialog pd = new ProgressDialog(LoginActivity.this, R.style.AppTheme_Dark_Dialog);
                        pd.setIndeterminate(true);
                        pd.setMessage("Authenticating...");
                        pd.show();
                        task.email = emailText.getText().toString();
                        task.pass = pwd.getText().toString();
                        task.context = LoginActivity.this;
                        task.progressDialog = pd;
                        emailText.setText("");
                        pwd.setText("");
                        task.execute();
                    }
                    // When Email is invalid
                    else {
                        emailText.setError("Please enter valid email");
                    }
                } else {
                    if (Utility.isNotNull(emailText.getText().toString())) {
                        pwd.setError("Please don't leave any field blank");
                    } else {
                        emailText.setError("Please don't leave any field blank");
                    }
                }
            }
        });
    }
    @Override
    public void onBackPressed() {
    }
    public void checkResponseCode(int code) {
        int root;
        switch (code) {
            case 402:
                root = R.id.payment_toast_layout;
                invokeToast(R.layout.paymentreq_login_toast, root);
                break;
            case 410:
                root = R.id.inactive_toast_layout;
                invokeToast(R.layout.inactive_login_toast, root);
                break;
            case 483:
                root = R.id.nouser_toast_layout;
                invokeToast(R.layout.nouser_login_toast, root);
        }
    }
    public void invokeToast(int id, int root) {
        LayoutInflater inflater = getLayoutInflater();
        View toastLayout = inflater.inflate(id, (ViewGroup) findViewById(R.id.payment_toast_layout));
        Toast toast = new Toast(getApplicationContext());
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(toastLayout);
        toast.show();
    }
}

查看解决方案,结果发现问题出在清单中,我试图在那里修复几行,但仍然没有帮助。我的日志再次是

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.symptoma.android/com.symptoma.android.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.symptoma.android.LoginActivity" on path: DexPathList[[zip file "/data/app/com.symptoma.android-3/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2546)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
                                                                              at android.app.ActivityThread.access$900(ActivityThread.java:177)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:145)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5944)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
                                                                           Caused by: java.lang.ClassNotFoundException: Didn't find class "com.symptoma.android.LoginActivity" on path: DexPathList[[zip file "/data/app/com.symptoma.android-3/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
                                                                              at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                              at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2536)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760) 
                                                                              at android.app.ActivityThread.access$900(ActivityThread.java:177) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                              at android.os.Looper.loop(Looper.java:145) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5944) 
                                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                                              at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) 
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) 
                                                                            Suppressed: java.lang.ClassNotFoundException: com.symptoma.android.LoginActivity
                                                                              at java.lang.Class.classForName(Native Method)
                                                                              at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                                              at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                    ... 13 more
                                                                           Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

确保你的软件包名称在任何地方都是正确的(java文件,xml文件,AndroidManifest文件......)。

项目:转到构建路径 --> 配置构建路径 --> Java 构建路径 -->排序和导出。然后取消选中Android依赖项并检查所有第三方.jar(如果有)。

最新更新