簡體   English   中英

來自 Play 商店的 NullPointerException 報告

[英]NullPointerException report from play store

今天我收到了一個NullPointerException報告。 我無法在自己的手機上重現此 NullPointerException。

我真的找不到導致 NullPointerException 的原因。

這是報告:

java.lang.NullPointerException
at com.dsf.sdf.ManActivity$25.onTouch(ManActivity.java:445)
at android.view.View.dispatchTouchEvent(View.java:3762)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at com.android.internal.policy.impl.PhoneWindow$DecorView.
    (PhoneWindow.java:1674)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1109)
at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
at com.android.internal.policy.impl.PhoneWindow$DecorView.
    dispatchTouchEvent(PhoneWindow.java:1658)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.
    run(ZygoteInit.java:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)

這是第 936 行的代碼:

sdff.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            sdff.setBackgroundDrawable(getResources().
                getDrawable(R.drawable.pressed));
        } 

        else if (event.getAction() == MotionEvent.ACTION_UP) {
            if (play != null) {
                play.reset();
                play.release();
            }
        
            play = MediaPlayer.create(ManActivity.this,
                R.raw.sdff);
            play.start();
            sdff.setBackgroundDrawable(getResources().
                getDrawable(R.drawable.button));
        } 

        else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
            sdff.setBackgroundDrawable(getResources().
                getDrawable(R.drawable.button));
        }
    
        return false;
    }
});

這是一個簡單的按鈕,按下時會發出聲音。

那么是什么導致了異常呢?

編輯:

Code at line 445:

play = MediaPlayer.create(ManActivity.this,
    R.raw.bf);
play.start();
auth.setBackgroundDrawable(getResources().getDrawable(
    R.drawable.button));

Rajesh 是對的,代碼是什么 @ ManActivity.java:445(第 445 行)。 如果這是代碼,也可以將以下內容用作您的觸摸偵聽器。

    sdff.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                // dont use sdff, use v param that is passed in.
                v.setBackgroundDrawable(getResources()
                        .getDrawable(R.drawable.pressed));
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                if (play != null) {
                    play.reset();
                    play.release();
                }
                play = MediaPlayer.create(ManActivity.this,
                        R.raw.sdff);

                play.start();
                v.setBackgroundDrawable(getResources()
                        .getDrawable(R.drawable.button));
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                v.setBackgroundDrawable(getResources()
                        .getDrawable(R.drawable.button));
            }
            return false;
        }
    });

無論如何,您是否嘗試過調試您的應用程序? (在包資源管理器中右鍵單擊 Project > Debug As > Android Application )。 然后這將切換到調試視角。 找到斷點窗格(窗口 > 顯示視圖 > 斷點)。 單擊 Add JAva execption Breakpoint 按鈕(它是一個帶有“!”的“J”)。 輸入“Null”並雙擊出現的 NullPointerException”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM