是在一個自定義輪滑的viewpager裡的dispatchTouchEvent裡寫的toast。
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
stopScroll();
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
if((ev.getEventTime()-ev.getDownTime())<100)
{
Toast.makeText(context, getCurrentItem(), 0).show();//這裡出錯
}
startScroll();
break;
default:
break;
}
return super.dispatchTouchEvent(ev);
}
錯誤信息:
03-26 10:31:20.445: W/ResourceType(6672): No package identifier when getting value for resource number 0x00000001
03-26 10:31:20.445: E/InputEventReceiver(6672): Exception dispatching input event.
03-26 10:31:20.445: E/MessageQueue-JNI(6672): Exception in MessageQueue callback: handleReceiveCallback
03-26 10:31:20.449: E/MessageQueue-JNI(6672): android.content.res.Resources$NotFoundException: String resource ID #0x1
03-26 10:31:20.449: E/MessageQueue-JNI(6672): at android.content.res.Resources.getText(Resources.java:244)
03-26 10:31:20.449: E/MessageQueue-JNI(6672): at android.widget.Toast.makeText(Toast.java:268)
03-26 10:31:20.449: E/MessageQueue-JNI(6672): at com.example.baby.widget.AutoScrollViewPager.dispatchTouchEvent(AutoScrollViewPager.java:82)
03-26 10:31:20.449: E/MessageQueue-JNI(6672): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
Toast.makeTest方法有兩個參數,其中一個方法第二個參數是@StringRes int resId,也就是字符串資源id。。
所以你的getCurrentItem返回了int型,而這個值沒有對應的字符串
寫成這樣
Toast.makeText(context, getCurrentItem()+"", 0).show();