android应用程序在点击按钮时崩溃

i2loujxw  于 2021-06-27  发布在  Java
关注(0)|答案(4)|浏览(969)

我创建了两个活动,一个是mainactivity,另一个是cookieactivity。我试图通过单击主cookie中的图像来转到cookie活动,但单击后应用程序立即崩溃。我是android开发的新手。谢谢你帮我!
我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.applicationelharemelhazami">

    <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/Theme.ApplicationElharemElhazami">
        <activity android:name=".CookieActivity"></activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

主要活动:

package com.example.applicationelharemelhazami;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private ImageButton play;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.play = (ImageButton) findViewById(R.id.play);

        play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent otherActivity = new Intent(getApplicationContext(), CookieActivity.class);
                startActivity(otherActivity);
                finish();
            }
        });
    }
}

活动\u main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/name_wahed"
        android:textColor="@color/red"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.525"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.702" />

    <ImageButton
        android:id="@+id/play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/graven_logo"
        tools:layout_editor_absoluteX="11dp"
        tools:layout_editor_absoluteY="16dp"
        tools:ignore="MissingConstraints" />

</androidx.constraintlayout.widget.ConstraintLayout>

Cookie活动:

package com.example.applicationelharemelhazami;

//import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class CookieActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cookie);

    }
}

日志:

2021-01-08 13:08:33.424 2997-2997/? I/elharemelhazam: Late-enabling -Xcheck:jni
2021-01-08 13:08:33.444 2997-2997/? E/elharemelhazam: Unknown bits set in runtime_flags: 0x8000
2021-01-08 13:08:33.570 2997-2997/com.example.applicationelharemelhazami I/Perf: Connecting to perf service.
2021-01-08 13:08:33.580 2997-2997/com.example.applicationelharemelhazami I/FeatureParser: can't find curtana.xml in assets/device_features/,it may be in /vendor/etc/device_features
2021-01-08 13:08:33.588 2997-2997/com.example.applicationelharemelhazami E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2021-01-08 13:08:33.579 2997-2997/com.example.applicationelharemelhazami W/elharemelhazami: type=1400 audit(0.0:235986): avc: denied { read } for name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=25646 scontext=u:r:untrusted_app:s0:c65,c257,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
2021-01-08 13:08:33.628 2997-2997/com.example.applicationelharemelhazami D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.applicationelharemelhazami activity: com.example.applicationelharemelhazami.MainActivity@38f037c
2021-01-08 13:08:33.630 2997-2997/com.example.applicationelharemelhazami D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.applicationelharemelhazami activity: com.example.applicationelharemelhazami.MainActivity@38f037c
2021-01-08 13:08:33.650 2997-2997/com.example.applicationelharemelhazami W/elharemelhazam: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-01-08 13:08:33.651 2997-2997/com.example.applicationelharemelhazami W/elharemelhazam: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-01-08 13:08:33.658 2997-2997/com.example.applicationelharemelhazami D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.applicationelharemelhazami activity: com.example.applicationelharemelhazami.MainActivity@38f037c
2021-01-08 13:08:33.660 2997-2997/com.example.applicationelharemelhazami I/chatty: uid=10321(com.example.applicationelharemelhazami) identical 1 line
2021-01-08 13:08:33.663 2997-2997/com.example.applicationelharemelhazami D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.applicationelharemelhazami activity: com.example.applicationelharemelhazami.MainActivity@38f037c
2021-01-08 13:08:33.715 2997-3039/com.example.applicationelharemelhazami I/AdrenoGLES: QUALCOMM build                   : ed77089, I0c4fc4bb0e
    Build Date                       : 12/24/19
    OpenGL ES Shader Compiler Version: EV031.27.05.03
    Local Branch                     : 
    Remote Branch                    : 
    Remote Branch                    : 
    Reconstruct Branch               : 
2021-01-08 13:08:33.715 2997-3039/com.example.applicationelharemelhazami I/AdrenoGLES: Build Config                     : S P 8.0.12 AArch64
2021-01-08 13:08:33.718 2997-3039/com.example.applicationelharemelhazami I/AdrenoGLES: PFP: 0x016ee187, ME: 0x00000000
2021-01-08 13:08:33.735 2997-3039/com.example.applicationelharemelhazami W/Gralloc3: mapper 3.x is not supported
2021-01-08 13:08:34.731 2997-2997/com.example.applicationelharemelhazami I/Timeline: Timeline: Activity_launch_request time:443838815
2021-01-08 13:08:34.759 2997-2997/com.example.applicationelharemelhazami W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@176ca0d
2021-01-08 13:08:34.772 2997-2997/com.example.applicationelharemelhazami D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.applicationelharemelhazami activity: com.example.applicationelharemelhazami.CookieActivity@fd2fa09
2021-01-08 13:08:34.773 2997-2997/com.example.applicationelharemelhazami D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.applicationelharemelhazami activity: com.example.applicationelharemelhazami.CookieActivity@fd2fa09
2021-01-08 13:08:34.785 2997-2997/com.example.applicationelharemelhazami D/AndroidRuntime: Shutting down VM
2021-01-08 13:08:34.787 2997-2997/com.example.applicationelharemelhazami E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.applicationelharemelhazami, PID: 2997
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.applicationelharemelhazami/com.example.applicationelharemelhazami.CookieActivity}: android.view.InflateException: Binary XML file line #2 in com.example.applicationelharemelhazami:layout/activity_cookie: Binary XML file line #2 in com.example.applicationelharemelhazami:layout/activity_cookie: Error inflating class android.support.constraint.ConstraintLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3308)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7562)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: android.view.InflateException: Binary XML file line #2 in com.example.applicationelharemelhazami:layout/activity_cookie: Binary XML file line #2 in com.example.applicationelharemelhazami:layout/activity_cookie: Error inflating class android.support.constraint.ConstraintLayout
     Caused by: android.view.InflateException: Binary XML file line #2 in com.example.applicationelharemelhazami:layout/activity_cookie: Error inflating class android.support.constraint.ConstraintLayout
     Caused by: java.lang.ClassNotFoundException: android.support.constraint.ConstraintLayout
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at android.view.LayoutInflater.createView(LayoutInflater.java:819)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.applicationelharemelhazami.CookieActivity.onCreate(CookieActivity.java:13)
        at android.app.Activity.performCreate(Activity.java:7893)
        at android.app.Activity.performCreate(Activity.java:7880)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7562)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
2021-01-08 13:08:34.787 2997-2997/com.example.applicationelharemelhazami E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.applicationelharemelhazami-12cjP0_3sHnyiYT3ttbaHw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.applicationelharemelhazami-12cjP0_3sHnyiYT3ttbaHw==/lib/arm64, /system/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 26 more
piok6c0g

piok6c0g1#

问题解决了!我只是创建了一个新的项目,并重做同样的事情,不知何故它工作!谢谢你的回答,我真的很感激你的努力。

scyqe7ek

scyqe7ek2#

尝试使用相同类型的视图。在xml声明中添加一个imagebutton,在活动中尝试获取一些imageview。。。

f0ofjuux

f0ofjuux3#

问题是:您在activity\u main.xml中使用imagebutton,并在mainactivity.java中初始化为imageview
解决方案:在mainactivity.java中将imagebutton初始化为imagebutton,或者在activity\u main.xml中将imagebutton替换为imageview

baubqpgj

baubqpgj4#

替换您的私人imageview播放;按键播放;并替换this.play=(imageview)findviewbyid(r.id.play);toplay=findviewbyid(r.id.play);就这样。

相关问题