【问题标题】:Errors for the android Bluetooth Chat example: layout unkown and API free of modifications crashedandroid 蓝牙聊天示例的错误:布局未知和未修改的 API 崩溃
【发布时间】:2011-05-26 17:43:40
【问题描述】:

我尝试为我的应用程序实现蓝牙通信,但我仍然卡在发现设备部分。 因此,我尝试实现 google 提供的蓝牙聊天示例,但出现了一些错误。 事实上,Ecpise 告诉我必须导入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 cannot be resolved

我检查一下:

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

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

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

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

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

你有什么想法吗?你想要关于我的代码的其他精度吗?
感谢您的回答。


大家好,

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

但我无法将诺基亚连接到 htc 的愿望。我假设我必须使用具有相同应用程序的其他 android 手机。我会尽快做的。

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

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

【问题讨论】:

    标签: android eclipse bluetooth uuid


    【解决方案1】:

    如果您还没有这样做,请确保您在 manifest.xml 中设置了正确的权限

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

    【讨论】:

      【解决方案2】:

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

      您是否在您的字符串文件中添加了条目?

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

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

      【讨论】:

        【解决方案3】:

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

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

        在 BluetoothChatService.java 文件中:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-14
          • 1970-01-01
          • 2012-06-13
          • 1970-01-01
          • 2011-07-13
          相关资源
          最近更新 更多