소스부터 보여드리겠습니다.
버튼을 클릭하는 부분입니다.
locationService = new LocationService(); 여기는 onCreate에서 선언했다가 일로 옮겼습니다. 둘다 해봤습니다.
*locationService.register(id,lat,lng, 5, -1); 이 부분이 문제입니다. NullPointerEx*
private View.OnClickListener bHandler = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.busStopRefresh:
BusStopIdThread busStopIdThread = new BusStopIdThread();
busStopIdThread.execute(StopIdUrl + Id);
break;
case R.id.bmAdd:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(BusStopInfo.this);
alertDialog.setTitle("즐겨찾기편집");
final EditText input = new EditText(BusStopInfo.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
String stNm = "";
for(int i = 0; i < busStopItemArray.size(); i++){
stNm = busStopItemArray.get(i).getStNm();
}
input.setText(stNm);
input.setLayoutParams(lp);
alertDialog.setView(input);
alertDialog.setPositiveButton("등록",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(input.getText().length() != 0 && !input.equals("")){
String nickName = input.getText().toString();
String stId = "";
String stNm = "";
String arsId = "";
String busRouteId = "";
String rtNm = "";
String gpsX = "";
String gpsY = "";
bookMarkDBHelper = new BookMarkDBHelper(BusStopInfo.this,ROOT+BOOKMARK_DB_NAME,null,BOOKMARK_DB_VERSION);
for(int i = 0; i < busStopItemArray.size(); i++){
stId = busStopItemArray.get(i).getStId();
stNm = busStopItemArray.get(i).getStNm();
arsId = busStopItemArray.get(i).getArsId();
busRouteId = busStopItemArray.get(i).getBusRouteId();
rtNm = "";//busStopItemArray.get(i).getRtNm();
gpsX = busStopItemArray.get(i).getGpsX();
gpsY = busStopItemArray.get(i).getGpsY();
}
int id = Integer.parseInt(arsId);
double lat = Double.parseDouble(gpsY);
double lng = Double.parseDouble(gpsX);
int check = Check(arsId,"1");
switch (check) {
case 0:
receiveInfoInsert(nickName, stId, stNm, arsId, busRouteId, rtNm, gpsX, gpsY, "1");
locationService = new LocationService();
locationService.register(id,lat,lng, 5, -1);
break;
case 1:
Toast.makeText(BusStopInfo.this, "이미 등록된 정류소입니다.", Toast.LENGTH_SHORT).show();
break;
}
} else {
Toast.makeText(BusStopInfo.this, "내용을 입력해주세요.", Toast.LENGTH_SHORT).show();
}
}
});
alertDialog.setNegativeButton("취소",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
break;
}
}
};
여기는 근접경보를 받을 위치를 등록하고 onReceiver 로 보냅니다. Service로 구현 하였습니다.
PendingIntent intent = PendingIntent.getBroadcast(this,id,proximityIntent,PendingIntent.FLAG_CANCEL_CURRENT); NullPointerEx 납니다. 위에랑여기랑 두군데서 에러가납니다.
package org.jsb.busgod.busgod;
public class LocationService extends Service {
private static final String TAG = "LocationService";
private LocationManager locationManager;
private LocationReceiver locationReceiver;
private HashMap<Integer,PendingIntent> locationList;
private String intentKey = "org.jsb.busgod.busgod";
public LocationService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationList = new HashMap<Integer,PendingIntent>();
locationReceiver = new LocationReceiver(intentKey);
registerReceiver(locationReceiver,locationReceiver.getFilter());
//register(id,lat,lng,radius,expiration);
return super.onStartCommand(intent, flags, startId);
}
public void register(int id, double lat, double lng, float radius, long expiration){
Log.d(TAG,"id : " + id + ", lat : " + lat + ", lng : " + lng + ", radius : " + radius + ", expiration : " + expiration);
Intent proximityIntent = new Intent(intentKey);
proximityIntent.putExtra("id",id);
PendingIntent intent = PendingIntent.getBroadcast(this,id,proximityIntent,PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(lat,lng,radius,expiration,intent);
locationList.put(id,intent);
}
생략
}