执行记事本示例时出错

时间:2011-04-05 10:40:14

标签: android notepad

我正在测试http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html上给出的示例。

我已按照教程中提到的步骤进行操作。该应用程序已在模拟器中成功启动

enter image description here

但是当我点击菜单按钮时出现错误

enter image description here

当我在eclipse控制台中检查时,它没有显示任何错误。

当我在eclipse中打开DDMS透视图并转到文件资源管理器时。当我转到data / data / com.android.demo.notepad1 /时,在文件资源管理器中。我看到两个显示5120尺寸的文件夹。

在Log Cat下面出现以下错误:

04-05 16:19:07.267: ERROR/AndroidRuntime(345): FATAL EXCEPTION: main
04-05 16:19:07.267: ERROR/AndroidRuntime(345): android.content.res.Resources$NotFoundException: String resource ID #0x7f040002
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.content.res.Resources.getText(Resources.java:201)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.content.res.Resources.getString(Resources.java:254)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.internal.view.menu.MenuBuilder.add(MenuBuilder.java:397)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.demo.notepad1.Notepadv1.onCreateOptionsMenu(Notepadv1.java:45)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.app.Activity.onCreatePanelMenu(Activity.java:2158)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:323)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel(PhoneWindow.java:568)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.internal.policy.impl.PhoneWindow.onKeyDown(PhoneWindow.java:1210)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1668)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.os.Looper.loop(Looper.java:123)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at java.lang.reflect.Method.invokeNative(Native Method)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at java.lang.reflect.Method.invoke(Method.java:507)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-05 16:19:07.267: ERROR/AndroidRuntime(345):     at dalvik.system.NativeStart.main(Native Method)
04-05 16:19:07.366: WARN/ActivityManager(67):   Force finishing activity com.android.demo.notepad1/.Notepadv1
04-05 16:19:07.926: WARN/ActivityManager(67): Activity pause timeout for HistoryRecord{405525f0 com.android.demo.notepad1/.Notepadv1}
04-05 16:19:19.540: WARN/ActivityManager(67): Activity destroy timeout for HistoryRecord{405525f0 com.android.demo.notepad1/.Notepadv1}
04-05 16:20:39.455: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
04-05 16:24:11.534: INFO/Process(345): Sending signal. PID: 345 SIG: 9
04-05 16:24:12.428: ERROR/InputDispatcher(67): channel '406a5ed8 com.android.demo.notepad1/com.android.demo.notepad1.Notepadv1 (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
04-05 16:24:12.468: ERROR/InputDispatcher(67): channel '406a5ed8 com.android.demo.notepad1/com.android.demo.notepad1.Notepadv1 (server)' ~ Channel is unrecoverably broken and will be disposed!
04-05 16:24:12.572: INFO/ActivityManager(67): Process com.android.demo.notepad1 (pid 345) has died.
04-05 16:24:12.719: INFO/WindowManager(67): WIN DEATH: Window{406a5ed8 com.android.demo.notepad1/com.android.demo.notepad1.Notepadv1 paused=false}

请帮我找出导致此类错误的原因

由于

的Pankaj

2 个答案:

答案 0 :(得分:3)

我已经解决了这个问题。实际上,当我导入项目时,有drawable-hdpi,drawable-mdpi和drawable-ldpi文件夹的drawable文件夹。它引起了冲突。我删除了drawable文件夹并将其中的图像放入hdpi,mdpi& ldpi文件夹。现在,当我运行应用程序时,它按预期工作。

答案 1 :(得分:1)