我已经对上述错误进行了一些研究,似乎要解决大多数人的做法有两种:
但是我已经做了两件事,但我仍然得到同样的错误。有没有人知道其他任何方法可以解决这个错误?
我在想,这可能是我的代码。我正在尝试编译找到here
的蓝牙文件样本我带来了所有的东西,但我仍然遇到了36个错误,其中大多数是因为这不能解决为字段或类型错误。
以下是他们如何称呼吐司线:
Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
在values文件夹中找到strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">BLE Sample</string>
<string name="ble_not_supported">BLE is not supported</string>
<string name="label_data">Data:</string>
<string name="label_device_address">Device address:</string>
<string name="label_state">State:</string>
<string name="no_data">No data</string>
<string name="connected">Connected</string>
<string name="disconnected">Disconnected</string>
<string name="title_devices">BLE Device Scan</string>
<string name="error_bluetooth_not_supported">Bluetooth not supported.</string>
<string name="unknown_device">Unknown device</string>
<string name="unknown_characteristic">Unknown characteristic</string>
<string name="unknown_service">Unknown service</string>
<!-- Menu items -->
<string name="menu_connect">Connect</string>
<string name="menu_disconnect">Disconnect</string>
<string name="menu_scan">Scan</string>
<string name="menu_stop">Stop</string>
</resources>
我真的是第一次进入我的第一个Android开发阶段,这对我来说是全新的。我认为使用他们提供的示例代码可以帮助我更好地了解蓝牙系统的工作原理。
任何人都可以帮助我击败这个错误吗?
我应该补充一下,此列表中的每个项目都有错误。任何时候我用R.string调用任何东西。它得到了同样的错误。 Logcat自1:25 pm起:
09-06 13:25:20.901: E/(526): W/virtual loc_api_adapter_err LocApiAdapter::enableData(int): default implementation invoked
09-06 13:25:20.901: E/(526): W/virtual loc_api_adapter_err LocApiAdapter::setAPN(char*, int): default implementation invoked
09-06 13:25:20.911: D/PicasaUploaderSyncManager(25851): active network: NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "SOL2", roaming: false, failover: false, isAvailable: true
09-06 13:25:20.921: D/GCM(2565): GcmService start Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 cmp=com.google.android.gms/.gcm.GcmService (has extras) } android.net.conn.CONNECTIVITY_CHANGE
09-06 13:25:21.051: D/ConnectivityService(526): handleInetConditionHoldEnd: net=1, condition=100, published condition=0
09-06 13:25:21.542: D/Tethering(526): MasterInitialState.processMessage what=3
09-06 13:25:21.642: E/(526): W/virtual loc_api_adapter_err LocApiAdapter::enableData(int): default implementation invoked
09-06 13:25:21.642: E/(526): W/virtual loc_api_adapter_err LocApiAdapter::setAPN(char*, int): default implementation invoked
09-06 13:25:21.662: D/GCM(2565): GcmService start Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 cmp=com.google.android.gms/.gcm.GcmService (has extras) } android.net.conn.CONNECTIVITY_CHANGE
09-06 13:25:22.102: D/ConnectivityService(526): handleInetConditionHoldEnd: net=1, condition=100, published condition=100
09-06 13:30:01.245: V/DigitalWidgetViewsFactory(6453): DigitalWidget sets next alarm string to null
09-06 13:36:19.083: I/ActivityManager(526): No longer want com.google.android.talk (pid 26303): empty for 1801s
09-06 13:36:31.455: V/BackupManagerService(526): Running a backup pass
09-06 13:36:31.455: V/BackupManagerService(526): clearing pending backups
09-06 13:36:31.455: V/PerformBackupTask(526): Beginning backup of 1 targets
09-06 13:36:31.485: V/BackupServiceBinder(526): doBackup() invoked
09-06 13:36:31.485: D/PerformBackupTask(526): invokeAgentForBackup on @pm@
09-06 13:36:31.495: I/PerformBackupTask(526): no backup data written; not calling transport
09-06 13:36:31.506: D/PerformBackupTask(526): starting agent for backup of BackupRequest{pkg=com.android.providers.settings}
09-06 13:36:31.506: D/BackupManagerService(526): awaiting agent for ApplicationInfo{4202bfe0 com.android.providers.settings}
09-06 13:36:31.506: D/BackupManagerService(526): agentConnected pkg=com.android.providers.settings agent=android.app.backup.BackupAgent$BackupServiceBinder@42081138
09-06 13:36:31.506: I/BackupManagerService(526): got agent android.app.backup.BackupAgent$BackupServiceBinder@42081138
09-06 13:36:31.506: D/PerformBackupTask(526): invokeAgentForBackup on com.android.providers.settings
09-06 13:36:31.516: V/BackupServiceBinder(526): doBackup() invoked
09-06 13:36:31.526: W/SettingsBackupAgent(526): Couldn't backup /data/misc/wifi/ipconfig.txt
09-06 13:36:31.526: I/PerformBackupTask(526): no backup data written; not calling transport
09-06 13:36:31.526: I/PerformBackupTask(526): Backup pass finished.
09-06 13:39:59.999: I/ActivityManager(526): No longer want com.google.android.music:main (pid 26385): empty for 1849s
09-06 13:40:00.099: W/ActivityManager(526): Scheduling restart of crashed service com.google.android.music/.playback.MusicPlaybackService in 5000ms
09-06 13:40:05.134: I/ActivityManager(526): Start proc com.google.android.music:main for service com.google.android.music/.playback.MusicPlaybackService: pid=27303 uid=10041 gids={50041, 3003, 1015, 1028}
09-06 13:40:05.214: I/MusicStore(27303): Database version: 70
09-06 13:40:05.274: D/dalvikvm(27303): GC_CONCURRENT freed 315K, 4% free 9097K/9448K, paused 3ms+9ms, total 39ms
09-06 13:40:05.274: D/dalvikvm(27303): WAIT_FOR_CONCURRENT_GC blocked 2ms
09-06 13:40:05.284: D/dalvikvm(27303): WAIT_FOR_CONCURRENT_GC blocked 5ms
09-06 13:40:05.364: D/SystemUtils(27303): getSystemProperty: lpa.decode=null
09-06 13:40:05.364: D/CacheService(27303): onCreate
09-06 13:40:05.374: D/CacheService(27303): onBind
09-06 13:40:05.384: I/LocalDevicePlayback(27303): Streaming client created.
09-06 13:40:06.445: D/dalvikvm(27303): GC_CONCURRENT freed 181K, 3% free 9337K/9580K, paused 4ms+4ms, total 30ms
09-06 13:40:06.535: I/MediaStoreImporter(27303): Update: incremental Added music: 0 Updated music: 0 Deleted music: 0 Created playlists: 0 Updated playlists: 0 Deleted playlists: 0 Inserted playlist items: 0 Deleted playlist items: 0 Removed orphaned playlist items: 0
09-06 13:40:10.459: I/MusicLeanback(27303): Conditions not met for autocaching.
09-06 13:40:10.459: I/MusicLeanback(27303): Stop autocaching.
09-06 13:40:20.549: D/GCM(2565): Ignoring attempt to send heartbeat on dead connection.
09-06 13:40:59.997: I/ActivityManager(526): No longer want android.process.acore (pid 26550): empty for 1807s
09-06 13:45:01.283: V/DigitalWidgetViewsFactory(6453): DigitalWidget sets next alarm string to null
09-06 13:48:16.403: I/EventLogService(2565): Aggregate from 1378470317827 (log), 1378469896229 (data)
09-06 13:48:16.533: I/ServiceDumpSys(2565): dumping service [account]
09-06 13:50:23.497: I/jdwp(24586): Ignoring second debugger -- accepting and dropping
09-06 13:50:23.507: I/jdwp(20948): Ignoring second debugger -- accepting and dropping
09-06 13:50:34.378: D/dalvikvm(526): GC_CONCURRENT freed 3407K, 27% free 23292K/31488K, paused 11ms+8ms, total 146ms
09-06 13:52:43.224: D/ChildProcessLauncher(5790): Setting up connection to process: slot=2
09-06 13:52:43.224: I/ActivityManager(526): Start proc com.android.chrome:sandboxed_process2 for service com.android.chrome/org.chromium.content.app.SandboxedProcessService2: pid=27469 uid=99002 gids={}
09-06 13:52:43.244: I/ChildProcessService(27469): Creating new ChildProcessService pid=27469
09-06 13:52:43.254: D/ChildProcessLauncher(5790): on connect callback, pid=27469 context=2105709408
09-06 13:52:43.254: I/LibraryLoader(27469): loading: chromeview
09-06 13:52:43.304: I/LibraryLoader(27469): loaded: chromeview
09-06 13:52:43.304: I/chromium(27469): [INFO:library_loader_hooks.cc(72)] Chromium logging enabled: level = 0, default verbosity = 0
09-06 13:52:43.314: D/TraceEvent(27469): View tag enabled: false
09-06 13:52:43.334: I/chromium(27469): [INFO:child_process_service.cc(132)] ChildProcessService: Exiting child process.
09-06 13:52:43.344: W/ChildProcessConnection(5790): onServiceDisconnected (crash?): pid=27469
09-06 13:52:43.344: D/ChildProcessLauncher(5790): stopping child connection: pid=27469
09-06 13:52:43.344: I/ActivityManager(526): Process com.android.chrome:sandboxed_process2 (pid 27469) has died.
09-06 13:52:43.344: W/ActivityManager(526): Scheduling restart of crashed service com.android.chrome/org.chromium.content.app.SandboxedProcessService2 in 5000ms
答案 0 :(得分:1)
尝试像这样展示吐司:
Toast.makeText(context, context.getString(R.string.error_bluetooth_not_supported),Toast.LENGTH_LONG).show();
此处上下文指的是显示Toast的当前活动的上下文。
答案 1 :(得分:0)
1)通常,在构建项目之后,所有 R.string.stuff 都不再是错误,因为在构建期间生成了文件R.java。如果您尚未构建项目,它们将显示为错误,这是正常的。顺便说一下,在Eclipse中,您可以在错误消息窗口中手动删除错误消息(您可以选择并删除一个或多个错误,但不能删除读取“错误(N个项目)”的根节点)。在“包资源管理器”(左侧)窗格中选择项目时,再次按“F5”(“刷新”)一次“魔术”传递。
2)确保生成的R类属于与使用它的类相同的包。在Eclipse中,您必须在“Package Explorer”窗格中看到: YourProject - gen - your.package - R.java。 (如果该文件不存在,文件夹是读/写吗?)
3)创建一个空项目并将google源代码移动到它可能比尝试从git编译项目更容易。至少有一些谷歌应用程序项目使用的目录结构与您通常使用Eclipse的目录结构不同(因为它们是使用特殊脚本构建的)。
答案 2 :(得分:0)
通常,当资源文件夹中存在任何错误时,R.Java文件无法正确创建,因此您将收到此类错误。请检查布局文件夹或可绘制文件夹中是否有任何错误。
答案 3 :(得分:-1)
使用:
Toast.makeText(this, getResources().getText(R.string.error_bluetooth_not_supported).toString(), Toast.LENGTH_SHORT).show();
你可以使用:
String str = getResources().getText(R.string.error_bluetooth_not_supported).toString();