【问题标题】:No Class found Error while using BeaconManager使用 BeaconManager 时找不到类错误
【发布时间】:2015-01-22 07:27:57
【问题描述】:

我正在开发一个使用 Estimote SDK for Beacons 的应用程序。我已经成功地将罐子添加到我的项目中,并且还使用了 BeaconManager 类来检查设备蓝牙的状态。现在,每当我启动我的应用程序时,它每次都会崩溃。

以下是我在应用程序崩溃时得到的 logcat 代码:-

Toast.makeText(this, "Checking Bluetooth Status", Toast.LENGTH_LONG).show();
        if (!beaconManager.hasBluetooth()) {
          Toast.makeText(this, "Device does not have Bluetooth Low Energy", Toast.LENGTH_LONG).show();
          return;
        }

        // If Bluetooth is not enabled, let user enable it.
        if (!beaconManager.isBluetoothEnabled()) {
          Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
          startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        } else {
          //connectToService();
            Toast.makeText(mContext, " "+"Start Searching for Beacons", 0).show();
        }

Logcat 是:-

01-23 12:54:15.629: E/dalvikvm(24896): Could not find class 'com.estimote.sdk.BeaconManager', referenced from method com.example.beaconproject.HomeScreen.onCreate
01-23 12:54:15.769: E/AndroidRuntime(24896): FATAL EXCEPTION: main
01-23 12:54:15.769: E/AndroidRuntime(24896): java.lang.NoClassDefFoundError: com.estimote.sdk.BeaconManager
01-23 12:54:15.769: E/AndroidRuntime(24896):    at com.example.beaconproject.HomeScreen.onCreate(HomeScreen.java:24)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.app.Activity.performCreate(Activity.java:5372)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.os.Looper.loop(Looper.java:176)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at android.app.ActivityThread.main(ActivityThread.java:5419)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at java.lang.reflect.Method.invokeNative(Native Method)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at java.lang.reflect.Method.invoke(Method.java:525)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
01-23 12:54:15.769: E/AndroidRuntime(24896):    at dalvik.system.NativeStart.main(Native Method)

我的清单文件如下:-

  <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="21" />

    <!-- Needed permissions in order to scan for beacons. -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <!-- Declaration that this app is usable on phones with Bluetooth Low Energy. -->
    <uses-feature
        android:name="android.hardware.bluetooth_le"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".HomeScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service
            android:name="com.estimote.sdk.service.BeaconService"
            android:exported="false" />

谁能帮我解决这个问题。任何帮助都是不言而喻的。 谢谢。

【问题讨论】:

  • 如果您使用的是eclipse,您是否对您的jars 做了add to path
  • 是的,我只使用 Eclipse,我已经这样做了。
  • 您如何将 Estimote sdk 库添加到您的项目中?外部 jar,在 libs 文件夹内,作为外部库项目..?
  • 我尝试了两件事,首先我只是将 jar 复制到 libs 文件夹,其次我通过添加外部 jar 使用构建路径完成。

标签: android bluetooth ibeacon ibeacon-android estimote


【解决方案1】:

Eclipse 无法很好地导入项目。看this tutorial如何正确操作。

【讨论】:

  • 我猜它只是由于 Eclipse。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-25
  • 1970-01-01
  • 1970-01-01
  • 2015-10-18
  • 1970-01-01
相关资源
最近更新 更多