我正在开发一个应用程序,并且我收到了通知。通知显示当前位置和一些位置,这里我在openNotification上得到 IllegaleArgumentException 。
以下是我的代码:
public class ShowMapActivity extends FragmentActivity implements LocationListener {
GoogleMap _googleMap;
LocationManager locationManger;
TextView addressTextView,cTimeTextView;
GcmIntentService serv;
Context mContext;
private LatLng jamPositions;
private LatLng myCurrentPosition;
private double ctim;
private String adr;
private double jamLatitude;
private double jamLngitute;
JsonParserForNotification Jsonparser;
NotificationMapDetatilsDTO details;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
serv=new GcmIntentService();
setContentView(R.layout.activity_show_map);
// Get parse data For Notification
Jsonparser = new JsonParserForNotification();
details = new NotificationMapDetatilsDTO();
addressTextView = (TextView)findViewById(R.id.addressId);
cTimeTextView = (TextView)findViewById(R.id.ctimeId);
Intent noticeIntent = getIntent();
String message = noticeIntent.getExtras().getString("message");
NotificationMapDetatilsDTO notDetails=Jsonparser.Parser(message);
jamLatitude=notDetails.getLat();
jamLngitute = notDetails.getLng();
adr = notDetails.getAddr();
ctim = notDetails.getCtime();
Log.e("LATSHOW", ""+jamLatitude);
Log.e("LNGSHOW", ""+jamLngitute);
Log.e("CTIMESHOW", ""+ctim);
Log.e("ADDSHOW", adr);
addressTextView.setText(adr);
cTimeTextView.setText(""+ctim);
int status =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status!=ConnectionResult.SUCCESS){
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
else{
_googleMap = ((SupportMapFragment)
getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
_googleMap.getUiSettings().setZoomControlsEnabled(true);
_googleMap.getUiSettings().setCompassEnabled(true);
_googleMap.getUiSettings().setMyLocationButtonEnabled(true);
LocationManager service =
(LocationManager)getSystemService(LOCATION_SERVICE);
boolean enableGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean enableWiFi= service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, true);
//Location location = service.getLastKnownLocation(provider);
service.requestLocationUpdates(provider, 0, 0, this);
}
/*if(!enableGPS || !enableWiFi){
Toast.makeText(ShowMapActivity.this, "GPS signal not found",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}*/
//locationManger = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if(_googleMap==null){
Toast.makeText(getApplicationContext(), "Google Map Not Available",
Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.show_map, menu);
return true;
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
//locationManger.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
this);
if(location!=null){
_googleMap.clear();
double currentLatitude = location.getLatitude();
double currentLangitude = location.getLongitude();
myCurrentPosition = new LatLng(currentLatitude, currentLangitude);
jamPositions =new LatLng(jamLatitude, jamLngitute);
// Show Current Location
_googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myCurrentPosition,10));
_googleMap.addMarker(new MarkerOptions().position(myCurrentPosition)
.title("start"));
// Shows Jam Locations
_googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(jamPositions,10));
_googleMap.addMarker(new MarkerOptions().position(jamPositions)
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.flat(true));
}
// Getting Routes From Current Location TO Jam Location
getRoutes();
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
private void getRoutes(){
GMapV2Direction md = new GMapV2Direction();
org.w3c.dom.Document doc = md.getDocument(myCurrentPosition, jamPositions,
GMapV2Direction.MODE_DRIVING);
ArrayList<LatLng> directionPoint = md.getDirection(doc);
int distanceTime = md.getDistanceValue(doc);
int durationTime = md.getDurationValue(doc);
/*String startAddress = md.getStartAddress(doc);
String endAddress = md.getEndAddress(doc);*/
Log.e("DISTANCE",""+distanceTime);
Log.e("DURATION",""+durationTime);
if(durationTime/60 < ctim){
PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.RED);
for(int i = 0 ; i < directionPoint.size() ; i++) {
rectLine.add(directionPoint.get(i));
}
_googleMap.addPolyline(rectLine);
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
_googleMap.clear();
}
}
LogCat错误跟踪:
03-12 16:22:18.484: E/AndroidRuntime(3000): FATAL EXCEPTION: main
03-12 16:22:18.484: E/AndroidRuntime(3000): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.technowellServices.traffic/com.technowellServices.traffic.ShowMapActivity}: java.lang.IllegalArgumentException: provider==null
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1728)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1747)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.app.ActivityThread.access$1500(ActivityThread.java:155)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.os.Handler.dispatchMessage(Handler.java:130)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.os.Looper.loop(SourceFile:351)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.app.ActivityThread.main(ActivityThread.java:3814)
03-12 16:22:18.484: E/AndroidRuntime(3000): at java.lang.reflect.Method.invoke(Method.java:538)
03-12 16:22:18.484: E/AndroidRuntime(3000): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-12 16:22:18.484: E/AndroidRuntime(3000): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
03-12 16:22:18.484: E/AndroidRuntime(3000): at dalvik.system.NativeStart.main(Native Method)
03-12 16:22:18.484: E/AndroidRuntime(3000): Caused by: java.lang.IllegalArgumentException: provider==null
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:476)
03-12 16:22:18.484: E/AndroidRuntime(3000): at com.technowellServices.traffic.ShowMapActivity.onCreate(ShowMapActivity.java:121)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
03-12 16:22:18.484: E/AndroidRuntime(3000): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1692)
答案 0 :(得分:1)