从Android Market NullPointerException异常报告 [英] NullPointerException report from android market

查看:207
本文介绍了从Android Market NullPointerException异常报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个用户提交了以下崩溃报告:

A user submitted the following crash report:

java.lang.NullPointerException
at android.widget.TextView.onTouchEvent(TextView.java:7202)
at android.view.View.dispatchTouchEvent(View.java:3778)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:886)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:886)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:886)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:886)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:886)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1716)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1124)
at android.app.Activity.dispatchTouchEvent(Activity.java:2125)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1700)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1822)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5068)
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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

我无法重现它在我的任何测试手机(的Xperia,HTC Desire的,银河S)(或模拟器),错误报告并没有告诉我在哪里应用中的问题还是什么设备上(用户是谁或者这样我就可以向他们要更多有关他们在做什么导致它)。我不能在code发现任何地方,我明明尝试使用通过findViewById一个TextView没有检查,如果它是空第一。 XML文件中都没有安卓的onclick 在其中,所以它不是试图调用错误输入功能或类似的东西。我试着比较提供给Android源的线条,但他们似乎并没有直接匹配,和阅读的命名方法的源并没有帮助我。 (免责声明:我只使用Java进行了几个月)

I can't reproduce it on any of my test phones (Xperia, HTC Desire, Galaxy S) (or the emulators), and the error report doesn't tell me where in the app the problem is or on what device (or who the user was so I can ask them for more information about what they were doing that caused it). I can't find anywhere in the code where I obviously try to use a TextView via findViewById without checking if it's null first. None of the xml files have android:onclick in them, so it's not trying to call a mistyped function or something like that. I tried comparing the lines given to the android source, but they don't seem to match directly, and reading the source of the named methods hasn't helped me. (Disclaimer: I've only been using Java for a couple of months.)

任何人有任何想法,我应该检查什么吗?

Anyone have any idea what else I should check?

ETA:这只是我有一个touchlistener代替clicklistener地方是在这里:

ETA: This is only place I have a touchlistener instead of a clicklistener is here:

btnDelete.setOnTouchListener(new View.OnTouchListener()
{
  public boolean onTouch(View v, MotionEvent meMotion)
  {
    int iAction = meMotion.getAction();

    switch (iAction)
    {
      case MotionEvent.ACTION_DOWN:
        if (false == bKeyPressed)
        {
          bKeyPressed = true;
          deleteANumber();
        }
        mHandler.removeCallbacks(mDeleteTouch);
        mHandler.postAtTime(mDeleteTouch, SystemClock.uptimeMillis()
          + BUTTON_DELAY);
        break;
      case MotionEvent.ACTION_UP:
        bKeyPressed = false;
        mHandler.removeCallbacks(mDeleteTouch);
        break;
    }

    return true;
  }
});

其中mDeleteTouch为

where mDeleteTouch is

private final Runnable mDeleteTouch = new Runnable()
{
  public void run()
  {
    // delete a number from the display
    deleteANumber();

    // then call self in BUTTON_DELAY ms, unless cancelled
    mHandler.postAtTime(this, SystemClock.uptimeMillis() + BUTTON_DELAY);
  }
};

和deleteANumber()是

and deleteANumber() is

protected void deleteANumber()
{
  String strNumber = tvNumber.getText().toString();

  // only remove a character if there is at least one:
  if (strNumber.length() > 0)
  {
    strNumber = strNumber.substring(0, strNumber.length() - 1);
    tvNumber.setText(strNumber);
  }
}

这似乎是它可能是因为你不能调用null.length()的问题,但tvNumber用其文本设置为创造,所以gettext的()。toString()方法应该总是返回一个非空值吧?

which seems like it could be the problem as you can't call null.length(), but tvNumber is created with its text set to "", so getText().toString() should always return a non null value, right?

ETA2 我已经成功地得到了HTC的Desire HD相同的错误,但它似乎没有要回我的code崩溃 - 立即设置断点内部的onClick没有按' ŧ抓到任何东西。

ETA2 I've managed to get the same error on an HTC Desire HD, but it seems to crash without going back into my code -- setting breakpoints immediately inside the onClick doesn't catch anything.

ETA3 如果我注释掉 tvNumber.setInputType(InputType.TYPE_CLASS_NUMBER); 问题消失

ETA3 If I comment out tvNumber.setInputType(InputType.TYPE_CLASS_NUMBER); the problem goes away.

推荐答案

在了HTC的Desire HD,接触带有setInputType(InputType.TYPE_CLASS_NUMBER)设定一个TextView似乎抛出NullPointerException。离开那个列明prevents崩溃,但就必须手动输入过滤(这是不是在我的情况的问题,但可能是其他人的)。不是一个很好的解决方案,但解决nethertheless。

On the HTC Desire HD, touching a TextView with setInputType(InputType.TYPE_CLASS_NUMBER) set appears to throw a NullPointerException. Leaving that setting out prevents the crash, but necessitates manual input filtering (which isn't a problem in my case, but probably is in other people's). Not a good solution, but a solution nethertheless.

这篇关于从Android Market NullPointerException异常报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆