При нажатии на кнопку должна открыться вторая активити, но приложение крашится. Много чего нагуглил уже, ничего не помогло. Привожу ниже код.
Заранее спасибо!
Первая активити
package com.example.myfirstapplication;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.View;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AuthActivity extends AppCompatActivity {
private EditText mLogin;
private EditText mPassword;
private Button mEnter;
private Button mRegister;
private View.OnClickListener mOnEnterClickListener = new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if (isEmailValid() && isPassValid())
{
Intent intent = new Intent(AuthActivity.this, PACT.class);
intent.putExtra(PACT.EMAIL_KEY, mLogin.getText().toString());
intent.putExtra(PACT.PASS_KEY, mPassword.getText().toString());
startActivity(intent);
} else {
showError(R.string.login_error);
}
}
};
private View.OnClickListener mOnRegClickListener = new View.OnClickListener() {
@Override
public void onClick(View view)
{
//todo Обработка нажатия по кнопке
}
};
private boolean isEmailValid() {
return !TextUtils.isEmpty(mLogin.getText())
&& Patterns.EMAIL_ADDRESS.matcher(mLogin.getText()).matches();
}
private boolean isPassValid() {
return !TextUtils.isEmpty(mPassword.getText());
}
private void showError(@StringRes int string)
{
Toast.makeText(this, string, Toast.LENGTH_LONG).show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_auth);
mLogin = findViewById(R.id.etLogin);
mPassword = findViewById(R.id.etPass);
mEnter = findViewById(R.id.buttonEnter);
mRegister = findViewById(R.id.buttonRegister);
mEnter.setOnClickListener(mOnEnterClickListener);
mRegister.setOnClickListener(mOnRegClickListener);
}
}
XML для первой активити
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<EditText
android:id="@+id/etLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:hint="@string/login_Hint"/>
<EditText
android:id="@+id/etPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:inputType="textPassword"
android:hint="@string/pass_Hint"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/buttonEnter"
android:layout_weight="1"
android:text="@string/enter_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/buttonRegister"
android:layout_weight="1"
android:text="@string/reg_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Вторая активити
package com.example.myfirstapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class PACT extends AppCompatActivity {
private TextView mLogin;
private TextView mPassword;
private ImageView mPhoto;
public static String EMAIL_KEY="EMAIL_KEY";
public static String PASS_KEY="PASS_KEY";
private View.OnClickListener mOnPhotoClickListener = new View.OnClickListener() {
@Override
public void onClick(View view)
{
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pact);
mLogin = findViewById(R.id.tvEmail);
mPassword = findViewById(R.id.tvPass);
mPhoto = findViewById(R.id.tvPhoto);
Bundle bundle = getIntent().getExtras();
mLogin.setText(bundle.getString(EMAIL_KEY));
mPassword.setText(bundle.getString(PASS_KEY));
mPhoto.setOnClickListener(mOnPhotoClickListener);
}
}
XML второй активити
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/tvPhoto"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="16dp"/>
<LinearLayout
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:text="@string/email"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:id="@+id/tvEmail"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:text="@string/password"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:id="@+id/tvPass"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Манифест
<?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.example.myfirstapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".PACT"></activity>
<activity android:name=".AuthActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Текст ошибки
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapplication/com.example.myfirstapplication.PACT}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.support.v7.widget.AppCompatImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2906)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1605)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6642)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.support.v7.widget.AppCompatImageView
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.AppCompatImageView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.AppCompatImageView" on path: DexPathList[[zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/base.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_resources_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:610)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.myfirstapplication.PACT.onCreate(PACT.java:30)
at android.app.Activity.performCreate(Activity.java:7057)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunc
hActivity(ActivityThread.java:2784)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2906)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1605)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6642)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.myfirstapplication-h9Qvq9jZ02mWspjLRkxphQ==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:353)
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.<init>(DexFile.java:74)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
at dalvik.system.DexPathList.<init>(DexPathList.java:157)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:681)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:714)
at android.app.LoadedApk.getResources(LoadedApk.java:941)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2254)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673)
... 6 more
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.myfirstapplication"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
gradle.propetries
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
ImageView
androidx
, а вы пытаетесь использовать изsupport
. Покажите в вопросе содержимоеbuild.gradle (module app)
иgradle.properties