这是我关于 stackoverflow 的第一个问题,但几个月来我一直在使用您已经生成的资源,我必须说这真的很酷。非常感谢那些实现它的人!
我正在尝试在弹出窗口中创建手势识别(用户绘图,应用程序识别绘图)。当用户选择列表中的元素时,会创建弹出窗口。
应用程序在启动后崩溃,我从列表中选择元素。
带有手势监听器的弹出窗口:
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View pView = inflater.inflate(R.layout.gestures_layout_view, null, false);
final PopupWindow pw = new PopupWindow(pView);
pw.setFocusable(true);
pw.showAtLocation(this.findViewById(R.id.bag_list), Gravity.CENTER, 0, 0);
pw.update(300,300);
mLibrary = GestureLibraries.fromRawResource(mContext, R.raw.symbol);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(new OnGesturePerformedListener()
{
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
}
});
// button that allows to go back to inventory
ImageButton buttonExit = (ImageButton) pView.findViewById(R.id.exit_button_gestures_layout);
buttonExit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
pw.dismiss();
}
});
弹窗布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.gesture.GestureOverlayView
android:background="#0000ff"
android:id="@+id/gestures"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<ImageButton android:id="@+id/exit_button_gestures_layout" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
日志猫
05-23 09:06:50.293: D/AndroidRuntime(473): Shutting down VM
05-23 09:06:50.293: W/dalvikvm(473): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-23 09:06:50.293: E/AndroidRuntime(473): Uncaught handler: thread main exiting due to uncaught exception
05-23 09:06:50.303: E/AndroidRuntime(473): java.lang.NullPointerException
05-23 09:06:50.303: E/AndroidRuntime(473): at pl.maciej.traviddle.BagActivity.onListItemClick(BagActivity.java:318)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.app.ListActivity$2.onItemClick(ListActivity.java:312)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.widget.ListView.performItemClick(ListView.java:3285)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.os.Handler.handleCallback(Handler.java:587)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.os.Handler.dispatchMessage(Handler.java:92)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.os.Looper.loop(Looper.java:123)
05-23 09:06:50.303: E/AndroidRuntime(473): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-23 09:06:50.303: E/AndroidRuntime(473): at java.lang.reflect.Method.invokeNative(Native Method)
05-23 09:06:50.303: E/AndroidRuntime(473): at java.lang.reflect.Method.invoke(Method.java:521)
05-23 09:06:50.303: E/AndroidRuntime(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-23 09:06:50.303: E/AndroidRuntime(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-23 09:06:50.303: E/AndroidRuntime(473): at dalvik.system.NativeStart.main(Native Method)
05-23 09:06:50.313: I/dalvikvm(473): threadid=7: reacting to signal 3
05-23 09:06:50.313: E/dalvikvm(473): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
05-23 09:06:51.653: I/Process(473): Sending signal. PID: 473 SIG: 9
我已经在互联网上搜索过,但找不到任何有用的东西。
到目前为止,我注意到:
-> 如果我删除将侦听器分配给 GestureOverlayView 的代码,它一切正常,即创建弹出窗口并且用户可以绘制符号
-> 当我使用“实现”来实现手势监听器(如在http://developer.android.com/resources/articles/gestures.html中)而不是内联实现时,我得到了同样的错误
您能否告诉我为什么应用程序崩溃以及如何修复它?