Android 蓝牙聊天示例的错误:布局未知且 API 未修改崩溃

发布于 2024-11-10 02:31:25 字数 3314 浏览 2 评论 0原文

我尝试为我的应用程序实现蓝牙通信,但我仍然停留在发现设备部分。 因此,我尝试实现谷歌提供的蓝牙聊天示例,但出现一些错误。 事实上,Ecplise 告诉我必须导入 android.R,但我知道这是 Eclipse 的错误。看来主要问题是无法识别 xml 布局文件。

我从控制台中得到了一些错误:

[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\device_list.xml:8: error: Error: No resource found that matches the given name (at 'text' with value '@string/title_paired_devices').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\device_list.xml:23: error: Error: No resource found that matches the given name (at 'text' with value '@string/title_other_devices').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\device_list.xml:38: error: Error: No resource found that matches the given name (at 'text' with value '@string/button_scan').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\main.xml:26: error: Error: No resource found that matches the given name (at 'text' with value '@string/send').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\menu\option_menu.xml:4: error: Error: No resource found that matches the given name (at 'title' with value '@string/secure_connect').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\menu\option_menu.xml:8: error: Error: No resource found that matches the given name (at 'title' with value '@string/insecure_connect').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\menu\option_menu.xml:12: error: Error: No resource found that matches the given name (at 'title' with value '@string/discoverable').

然后,直接使用 android 文件中的 API,当 Eclipse 让我导入 com.example.android.BluetoothChat.R 时,我感到很惊讶。我做到了,之前的所有错误都消失了。我编译后,应用程序直接在模拟器和我的 Desire 上崩溃。

那么,您对我的问题有任何线索吗?是安卓版本问题吗?包裹丢失?日食错误?

为了您的关心,我没有触及蓝牙聊天示例的代码,而是尝试使用 2.1 和 3.0 android 版本进行编译。

所以,我想提前感谢您的帮助,无论它是什么:学习蓝牙 API 的线索或最简单的教程。

问候。


谢谢Lister,但我已经在Android Manifest中编写了两个蓝牙权限。 这不是我的问题的原因。

我刚刚读过这个: android.R 无法解析

我检查:

  • 包清单中的路径
  • java 文件中的包路径

我在相关文件中编写了 com.androidBthChat

然后,我尝试编译,在模拟器中运行该应用程序,但我刚刚遇到了相同的崩溃错误,路径包错误:

应用程序蓝牙聊天(进程 com.example.anndroid.BluetoothChat)已意外停止。 请重试。

因此,我们可以看到应用程序正在搜索错误的路径包。我是否必须使用 android 示例重新创建相同的路径包?

你有主意吗?您希望其他人了解我的代码的精度吗?
谢谢您的回答。


大家好,

我的问题几乎已经解决了。现在,我可以:
- 编译 Bth Chat android 项目没有错误,
- 启动时不会崩溃,
- 并发现设备(例如我的诺基亚手机)。

但我无法将诺基亚连接到 htc 希望。我假设我必须使用另一部具有相同应用程序的 Android 手机。我很快就会做的。

为了得到这个结果,我首先重新创建了整个项目,并从作者那里得到了建议: Oscilo_Bth。比照。 UUID_issue。 我将 UUID 更改为 00001101-0000-1000-8000-00805F9B34FB

我很快就会带着新结果回来。

I try to implement bluetooth communication for my application but I'm still stuck on the discover devices part.
So, I try to implement the Bluetooth Chat example provided by google but I get some errors.
Indeed, Ecplise tells me that I have to import android.R but I know that it is an error from Eclipse. It seems that the major issue is that xml layout files are not recognized.

I got some erros from my console:

[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\device_list.xml:8: error: Error: No resource found that matches the given name (at 'text' with value '@string/title_paired_devices').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\device_list.xml:23: error: Error: No resource found that matches the given name (at 'text' with value '@string/title_other_devices').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\device_list.xml:38: error: Error: No resource found that matches the given name (at 'text' with value '@string/button_scan').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\layout\main.xml:26: error: Error: No resource found that matches the given name (at 'text' with value '@string/send').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\menu\option_menu.xml:4: error: Error: No resource found that matches the given name (at 'title' with value '@string/secure_connect').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\menu\option_menu.xml:8: error: Error: No resource found that matches the given name (at 'title' with value '@string/insecure_connect').
[2011-05-26 15:30:46 - androidBthChat] E:\DATA\Simon\simon\Travail\Workspace_Eclipse\androidBthChat\res\menu\option_menu.xml:12: error: Error: No resource found that matches the given name (at 'title' with value '@string/discoverable').

Then, using directly the API in the android files, I was surprised when Eclipse offered me to import com.example.android.BluetoothChat.R. I did it and all the previous errors disappeared. I compiled and the application crash directly on the emuator and on my Desire.

So, do you have any clues for my problem? Is it android version issue? Missing package? Eclipse error?

For your concern, I didn't touch the code of Bluetooth Chat example and I tried to compile with 2.1 and 3.0 android version.

So, I want to thank you, in advance, for your help, whatever it is: clues or easiest tutorial to learn Bluetooth API.

Regards.


Thanks Lister but I have already written the two bluetooth permissions in the Android Manifest.
This is not the cause of my issue.

I just read this: android.R cannot be resolved

And I check:

  • Package path in the manifest
  • Package path in the java files

I wrote com.androidBthChat in the files concerned.

Then, I tried to compile, to run the application in the emulator and I just got the same crashed error with wrong path package:

The application Bluetooth Chat(process com.example.anndroid.BluetoothChat) has stopped unexpectedly.
Please try again.

So, we can see that the application is searching the wrong path package. Do i have to recreate the samed path package using android example?

Do you have an idea? Do you want others precisions regarding my code?

Thank you for your answers.


Hi All,

I have nearly resolved my problem. Now, I can:

- compile the Bth Chat android project without errors,

- launch without crash,

- and discover devices (my nokia cellphone for example).

But I can not connect the nokia to the htc desire. I assume that I have to use an other android phone with the same application. I will do it soon.

To get this result, I have first recreated the whole project and got advices from the author of this: Oscilo_Bth. Cf. UUID_issue.
I change the UUID to 00001101-0000-1000-8000-00805F9B34FB.

I will get back soon with new results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深空失忆 2024-11-17 02:31:25

如果您还没有这样做,请确保您已在manifest.xml 中添加了正确的权限。

我提到它是因为这是一个我重复了很多次直到我最终了解到的错误,所以也许其他人也会发生这种情况。我会花很多时间试图找出问题所在,然后我记住权限并将其放入,然后就可以了。

If you haven't already done it, make sure that you have put the right permissions in the manifest.xml

I mention it because it is a mistake I repeated many times until I finally learnt so maybe it happens to others as well. I would spend a lot of time trying to figure out what was wrong then I remember about the permissions and put them in and then it is OK.

瞎闹 2024-11-17 02:31:25

我遇到了一些类似的问题。

您是否将条目放入字符串文件中?

以下是蓝牙示例附带的字符串文件:

http:// /developer.android.com/resources/samples/BluetoothChat/res/values/strings.html

I ran into some similar issues.

Did you put entries in your strings file?

Here is the strings file that goes with the bluetooth example:

http://developer.android.com/resources/samples/BluetoothChat/res/values/strings.html

难理解 2024-11-17 02:31:25

注意:我可以编译该文件并将其上传到我的阿尔卡特 908,但程序由于某种原因崩溃了。

我所做的是获取 R.java 文件,该文件会导致我之前自己创建并正常工作的项目中的大部分错误(如果您是初学者,则不需要开发的应用程序,只需启动一个新的 android 项目和 R .java 将自动生成)。要在“项目”视图中找到此文件,请一直展开到 ProjectName/gen/com.PACKAGENAME/R.java

在 BluetoothChatService.java 文件中:

  • 搜索 listenUsingInsecureRfcommWithServiceRecord 并删除
    与此相关的代码。
  • 保持listenUsingRfcommWithServiceRecord不变。我也
    删除了 ActionBar 因为我不知道如何使用它:
  • 删除了导入和一些 setStatus 代码片段
    通过搜索文件就可以找到。我想应该是这样。

Note: I can compile the file and upload it to my Alcatel 908 but the program crashes for some reason.

What I did was get the R.java file that causes most of the errors from a project that I previously created myself and worked properly (you don't need a developed app if you are a beginner, just start a new android project and R.java will be automatically generated). To find this file in the Project view expand all the way to ProjectName/gen/com.PACKAGENAME/R.java

In BluetoothChatService.java file:

  • Search for listenUsingInsecureRfcommWithServiceRecord and delete
    the code related to this piece.
  • Leave the listenUsingRfcommWithServiceRecord untouched. I also
    removed the ActionBar because I don't know how to use it:
  • Removed the import and a few setStatus pieces of code which you
    could find by searching the file. I think this should be it.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文