Altbeacon安卓库2.1-beta2崩溃

时间:2015-01-15 14:09:57

标签: android ibeacon-android altbeacon

我知道这个版本不是用于生产目的,但我想知道这个例外是否只发生在我身上。 我有一个测试应用程序,当我尝试实例化BeaconManager时,我得到了下一个异常:

Unable to instantiate activity ComponentInfo{com.example.radiustesting/com.example.radiustesting.MainActivity}: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:94)
    at org.altbeacon.beacon.BeaconManager.verifyServiceDeclaration(BeaconManager.java:676)
    at org.altbeacon.beacon.BeaconManager.<init>(BeaconManager.java:215)

这是我简单的Activity类

public class MainActivity extends Activity  implements BeaconConsumer{
    protected static final String TAG = "RangingActivity";
    private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);

     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main_layout);
           beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0216,i:4-19,i:20-21,i:22-23,p:24-24"));
             // set the duration of the scan to be 1.1 seconds
            beaconManager.setBackgroundScanPeriod(1100l); 
            // set the time between each scan to be 1 hour (3600 seconds)
            beaconManager.setBackgroundBetweenScanPeriod(1000);

            beaconManager.bind(this);

        }
...

有人得到同样的例外吗? THX

1 个答案:

答案 0 :(得分:0)

public class MainActivity extends Activity  implements BeaconConsumer{
    protected static final String TAG = "RangingActivity";
    private BeaconManager;

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
       beaconManager = BeaconManager.getInstanceForApplication(this);
       beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0216,i:4-19,i:20-21,i:22-23,p:24-24"));
         // set the duration of the scan to be 1.1 seconds
        beaconManager.setBackgroundScanPeriod(1100l); 
        // set the time between each scan to be 1 hour (3600 seconds)
        beaconManager.setBackgroundBetweenScanPeriod(1000);

        beaconManager.bind(this);

    }