您好我正在使用here中的示例代码,但在构建应用时遇到错误。我已经下载了最新的iBeacon库android-beacon-library-2.7.tar.gz
,并按照网站上的说明添加到项目中。
这是MainActivity.class
package com.example.ibeacontest;
import android.util.Log;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.startup.BootstrapNotifier;
import android.app.Activity;
import android.graphics.Region;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "MonitoringActivity";
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager = BeaconManager.getInstanceForApplication(this);
// To detect proprietary beacons, you must add a line like below corresponding to your beacon
// type. Do a web search for "setBeaconLayout" to get the proper expression.
// beaconManager.getBeaconParsers().add(new BeaconParser().
// setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
public void onBeaconServiceConnect() {
beaconManager.setMonitorNotifier(new MonitorNotifier() {
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an beacon for the first time!");
}
public void didExitRegion(Region region) {
Log.i(TAG, "I no longer see an beacon");
}
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
} catch (RemoteException e) { }
}
}
错误:
Description Resource Path Location Type
The constructor Region(String, null, null, null) is undefined MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 56 Java Problem
The method startMonitoringBeaconsInRegion(org.altbeacon.beacon.Region) in the type BeaconManager is not applicable for the arguments (android.graphics.Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 56 Java Problem
The type new MonitorNotifier(){} must implement the inherited abstract method MonitorNotifier.didDetermineStateForRegion(int, Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 40 Java Problem
The type new MonitorNotifier(){} must implement the inherited abstract method MonitorNotifier.didEnterRegion(Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 40 Java Problem
The type new MonitorNotifier(){} must implement the inherited abstract method MonitorNotifier.didExitRegion(Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 40 Java Problem
可能是什么问题?
答案 0 :(得分:2)
其中一个import
语句指的是错误的包。只需更改:
import android.graphics.Region;
至import org.altbeacon.beacon.Region;
在我做出改变之前,我得到了与问题中显示的相同的错误。之后,代码编译成功。