3llomi / RecordView

A Simple Audio Recorder View with "hold to Record Button" and "Swipe to Cancel " Like WhatsApp
Apache License 2.0
367 stars 109 forks source link

How can I solve this error? #83

Closed Achisyg2 closed 2 years ago

Achisyg2 commented 2 years ago

Hello, I am using your library and I get the following error when I click on RecordButton: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.devlomi.record_view.RecordView.onActionDown(com.devlomi.record_view.RecordButton, android.view.MotionEvent)' on a null object reference at com.devlomi.record_view.RecordButton.onTouch(RecordButton.java:104) at android.view.View.dispatchTouchEvent(View.java:13479) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3088) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2724) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:496) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1853) at android.app.Activity.dispatchTouchEvent(Activity.java:4072) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:454) at android.view.View.dispatchPointerEvent(View.java:13744) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5601) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5401) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4902) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4955) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4921) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5061) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4929) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5118) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4902) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4955) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4921) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4929) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4902) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7654) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7623) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7584) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7785) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:251) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:336) at android.os.Looper.loop(Looper.java:180) at android.app.ActivityThread.main(ActivityThread.java:7562) at java.lang.reflect.Method.invoke(Native Method)

3llomi commented 2 years ago

Hey @Achisyg2, Please make sure to call

//IMPORTANT
recordButton.setRecordView(recordView);
Achisyg2 commented 2 years ago

@3llomi I have already called this.

Achisyg2 commented 2 years ago

Hey, @3llomi I added the line you mentioned above inside the onCreate function and worked. Thank you!!