长时间单击列表视图的第一项时,我的应用程序崩溃。实际上,第一项是手动添加的“转到文件夹”,并且在“转到文件夹”之后出现了列表视图项。列表中除“转到文件夹”项以外的所有项。
但是当我长按“转到文件夹”时,我的应用程序崩溃了。
我的代码的一小部分如下:

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);

最佳答案

当您单击“长按”时,它将尝试创建一个未设置的上下文菜单。请为项目设置上下文菜单,可能您的问题将得到解决。

07-24 09:49
查看更多