简体   繁体   English

Android Studio Application - java.lang.IllegalStateException: Could not execute method for android:onClick - Not a Null Pointer Exception

[英]Android Studio Application - java.lang.IllegalStateException: Could not execute method for android:onClick - Not a Null Pointer Exception

I am trying to upload a video from this app to firebase, but when I press the "publish button" I get this error that I have not encountered before.我正在尝试将此应用程序中的视频上传到 firebase,但是当我按下“发布按钮”时,我收到了这个我以前没有遇到过的错误。 I have done some research and some people who have got this error are actually just getting Null Pointer Exceptions, so I tried their fix and it didn't work.我已经做了一些研究,一些遇到此错误的人实际上只是得到 Null 指针异常,所以我尝试了他们的修复,但没有成功。 Any help is appreciated.任何帮助表示赞赏。

VideoPlayActivity.java VideoPlayActivity.java

public class VideoPlayActivity extends AppCompatActivity {

    private VideoView mVideoView;
    public static DatabaseReference mDatabase;
    public static Uri videoUri;
    public static String videoTitle;

    public static EditText videoTitleField;

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

        FirebaseDatabase database = FirebaseDatabase.getInstance();

        mDatabase = database.getInstance().getReference();

        mVideoView = findViewById(R.id.videoView);

        videoUri = Uri.parse(getIntent().getExtras().getString("videoUri"));

        mVideoView.setVideoURI(videoUri);

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });

        mVideoView.start();
    }

    public void publish(View view) {
        videoTitleField = findViewById(R.id.videoTitle);

        videoTitle = videoTitleField.getText().toString();

                if(videoTitle.equals("")) {
                    return;
                }

                mDatabase.child("videos").child(videoTitle).setValue(videoUri, new DatabaseReference.CompletionListener() {
                    @Override
                    public void onComplete(@Nullable DatabaseError databaseError, @NonNull DatabaseReference databaseReference) {
                        if (databaseError != null) {
                            System.out.println("Data could not be saved " + databaseError.getMessage());
                        } else {
                            System.out.println("Data saved successfully.");
                        }
                    }
                });

                Intent mainPage = new Intent(VideoPlayActivity.this, MainActivity.class);
                startActivity(mainPage);
    }
}

activity_video_play.xml activity_video_play.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="fill_parent"
    android:layout_height="fill_parent"
    android:background="#20FFFFFF"
    tools:context=".VideoPlayActivity">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"></VideoView>

    <Button
        android:id="@+id/publish"
        android:layout_width="match_parent"
        android:layout_height="62dp"
        android:layout_weight="1"
        android:background="#60FFFFFF"
        android:text="PUBLISH VIDEO"
        android:textSize="36sp"
        android:onClick="publish"/>

    <RelativeLayout
        android:id="@+id/coverView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:background="#74A6A6A6"
        android:visibility="visible"
        tools:ignore="RtlCompat">

        <EditText
            android:id="@+id/videoTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:ems="10"
            android:hint="Enter a Title"
            android:inputType="textPersonName"
            android:textSize="24sp"
            android:visibility="visible" />

    </RelativeLayout>

</RelativeLayout>

Logcat Error Logcat 错误

2020-06-08 10:39:56.988 20236-20236/com.example.resol E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.resol, PID: 20236
    java.lang.IllegalStateException: Could not execute method for android:onClick
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
        at android.view.View.performClick(View.java:6277)
        at android.view.View$PerformClick.run(View.java:24765)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6797)
        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:772)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
        at android.view.View.performClick(View.java:6277) 
        at android.view.View$PerformClick.run(View.java:24765) 
        at android.os.Handler.handleCallback(Handler.java:789) 
        at android.os.Handler.dispatchMessage(Handler.java:98) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6797) 
        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:772) 
     Caused by: java.lang.StackOverflowError: stack size 8MB
        at java.lang.reflect.Method.invoke(Native Method)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:657)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)

You are saving videoUri of type URI which is not valid argument for setValue function, so it is throwing IllegalStateException.您正在保存类型为 URI 的 videoUri,它不是 setValue function 的有效参数,因此它会抛出 IllegalStateException。 Instead call videoUri.toString().而是调用 videoUri.toString()。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalStateException:无法为 android 执行方法:onClick / ZE84E30B9390CDB67ZDDB6 - java.lang.IllegalStateException: Could not execute method for android:onClick / Android java.lang.IllegalStateException:无法执行android:onClick的方法 - java.lang.IllegalStateException: Could not execute method for android:onClick in android 错误:java.lang.IllegalStateException:无法执行android:onClick的方法 - Error: java.lang.IllegalStateException: Could not execute method for android:onClick Kotlin-java.lang.IllegalStateException:无法执行android:onClick的方法 - Kotlin - java.lang.IllegalStateException: Could not execute method for android:onClick Android Studio 问题; java.lang.IllegalStateException: 无法执行 android:onClick 的方法 - Android Studio problem ; java.lang.IllegalStateException: Could not execute method for android:onClick Android Studio 3.1.3 中的错误。 java.lang.IllegalStateException: 无法执行 android:onClick 的方法 - Error in Android Studio 3.1.3. java.lang.IllegalStateException: Could not execute method for android:onClick java.lang.IllegalStateException:无法执行 android:onClick 的方法。 应用程序崩溃 - java.lang.IllegalStateException: Could not execute method for android:onClick. Application crashes Android-Java:java.lang.IllegalStateException:无法执行 android 的方法:onClick - Android-Java: java.lang.IllegalStateException: Could not execute method for android:onClick ANDROID意图致命错误!!! java.lang.IllegalStateException: 无法执行 android:onClick 的方法 - ANDROID INTENTION FATAL ERROR!!! java.lang.IllegalStateException: Could not execute method for android:onClick java.lang.IllegalStateException:尝试单击按钮时无法执行android:onClick的方法 - java.lang.IllegalStateException: Could not execute method for android:onClick when trying to click a button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM