长按“列表”视图的“第一项”时,我的应用程序崩溃了。实际上第一项是“Go To Up Folder”,它是手动添加的,并且在“Go To Up Folder”列表视图项目到来之后。现在我正在使用长按“列出文件夹”项目以外的列表中的所有项目。 但是,当我长期点击“Go To Up Folder”时,我的应用程序崩溃了。 我的代码的一小部分如下:
if (tt != null)
{
if ((m_remotefilepath == null)|| (m_remotefilepath.matches("/")))
{
tt.setText(items[position].m_FileName);
}
else
{
if (position > 0)
{
tt.setText(items[position].m_FileName);
}
else
{
tt.setText("Go To Up Folder");
imageView.setImageResource(R.drawable.up);
}
}
}
我的日志猫:
04-27 12:06:21.635: DEBUG/AndroidRuntime(230): Shutting down VM
04-27 12:06:21.645: WARN/dalvikvm(230): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-27 12:06:21.686: ERROR/AndroidRuntime(230): Uncaught handler: thread main exiting due to uncaught exception
04-27 12:06:21.965: ERROR/AndroidRuntime(230): java.lang.NullPointerException
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at com.officelinq.android.OfficeLinQ.onCreateContextMenu(OfficeLinQ.java:1549)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.view.View.createContextMenu(View.java:4086)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at com.android.internal.view.menu.ContextMenuBuilder.show(ContextMenuBuilder.java:81)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at com.android.internal.policy.impl.PhoneWindow$DecorView.showContextMenuForChild(PhoneWindow.java:1848)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:458)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:458)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:458)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:458)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:458)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:458)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.widget.AbsListView.performLongPress(AbsListView.java:1703)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.widget.AbsListView.access$500(AbsListView.java:71)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:1656)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.os.Handler.handleCallback(Handler.java:587)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.os.Handler.dispatchMessage(Handler.java:92)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.os.Looper.loop(Looper.java:123)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at java.lang.reflect.Method.invoke(Method.java:521)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-27 12:06:21.965: ERROR/AndroidRuntime(230): at dalvik.system.NativeStart.main(Native Method)
04-27 12:06:22.235: INFO/Process(34): Sending signal. PID: 230 SIG: 3
04-27 12:06:22.285: INFO/dalvikvm(230): threadid=7: reacting to signal 3
04-27 12:06:22.963: INFO/dalvikvm(230): Wrote stack trace to '/data/anr/traces.txt'
第1549行的守则是: menu.setHeaderTitle(m_adapter.items [info.position] .m_FileName);
答案 0 :(得分:1)
当您进行“长”点击时,它正在尝试创建未设置的上下文菜单。请设置项目的上下文菜单,可能会解决您的问题。
答案 1 :(得分:0)
我今天也遇到了这个问题。它是由于使用SELECTION_MODE_MULTIPLE_MODAL而不调用ListView.setMultiChoiceModeListener()引起的。使用SELECTION_MODE_MULTIPLE或设置一个监听器使其消失。