my app loads up google maps and the user is drawing polylines in it... after he finishes the app sent his coordinates that he choose to another android device from his contacts list... now the problem is that when he draws more then 3 polylines when he is pressing the send button the app crashes and doesnt send an sms ... The app works up untill 3 polylines.. thats the logcat :
05-12 01:10:33.785: E/Gsm/SmsMessage(6255): hasUserDataHeader : false
05-12 01:12:00.970: E/AndroidRuntime(6255): FATAL EXCEPTION: main
05-12 01:12:00.970: E/AndroidRuntime(6255): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/data/43603 flg=0x1 (has extras) }} to activity {com.example.yeah/com.example.yeah.MainActivity}: java.lang.NullPointerException
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.os.Looper.loop(Looper.java:130)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-12 01:12:00.970: E/AndroidRuntime(6255): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 01:12:00.970: E/AndroidRuntime(6255): at java.lang.reflect.Method.invoke(Method.java:507)
05-12 01:12:00.970: E/AndroidRuntime(6255): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-12 01:12:00.970: E/AndroidRuntime(6255): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-12 01:12:00.970: E/AndroidRuntime(6255): at dalvik.system.NativeStart.main(Native Method)
05-12 01:12:00.970: E/AndroidRuntime(6255): Caused by: java.lang.NullPointerException
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.os.Parcel.readException(Parcel.java:1328)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.os.Parcel.readException(Parcel.java:1276)
05-12 01:12:00.970: E/AndroidRuntime(6255): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:613)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:109)
05-12 01:12:00.970: E/AndroidRuntime(6255): at com.example.yeah.MainActivity.onActivityResult(MainActivity.java:246)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.app.Activity.dispatchActivityResult(Activity.java:3934)
05-12 01:12:00.970: E/AndroidRuntime(6255): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
05-12 01:12:00.970: E/AndroidRuntime(6255): ... 11 more
and thats the main :
public class MainActivity extends FragmentActivity {
static boolean active = false;
@Override
public void onStart() {
super.onStart();
active = true;
}
@Override
public void onStop() {
super.onStop();
active = false;
}
public static boolean isActive(){
return active;
}
private static final int PICK_CONTACT = 1;
GoogleMap googleMap;
ArrayList<LatLng> points= new ArrayList<LatLng>() ;
Double glat;
Double glon;
//private final String UPDATE_MAP = "com.myco.myapp.UPDATE_MAP";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
googleMap = fm.getMap();
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
// Enabling buildings of Google Map
googleMap.setBuildingsEnabled(true);
googleMap.setOnMapLoadedCallback(new OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
Location lm = googleMap.getMyLocation();
if (lm!=null){
CameraPosition cp = new CameraPosition.Builder()
.target(new LatLng(lm.getLatitude(), lm.getLongitude()))
.zoom(17)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
}
}
});
// Setting OnClick event listener for the Google Map
googleMap.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
// Instantiating the class MarkerOptions to plot marker on the map
MarkerOptions markerOptions = new MarkerOptions();
// Setting latitude and longitude of the marker position
markerOptions.position(point);
// Setting titile of the infowindow of the marker
markerOptions.title("Position");
// Setting the content of the infowindow of the marker
markerOptions.snippet("Latitude:"+point.latitude+","+"Longitude:"+point.longitude);
// Instantiating the class PolylineOptions to plot polyline in the map
PolylineOptions polylineOptions = new PolylineOptions();
// Setting the color of the polyline
polylineOptions.color(Color.BLUE);
// Setting the width of the polyline
polylineOptions.width(6);
// Adding the taped point to the ArrayList
points.add(point);
// Setting points of polyline
polylineOptions.addAll(points);
// Adding the polyline to the map
googleMap.addPolyline(polylineOptions);
// Adding the marker to the map
googleMap.addMarker(markerOptions);
}
});
//Intent intent = new Intent("my.action.string");
//intent.putExtra("extra", fm);
//sendBroadcast(intent);
googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng point) {
// Clearing the markers and polylines in the google map
googleMap.clear();
// Empty the array list
points.clear();
}
});
if (points != null){
Button pickContact = (Button) findViewById(R.id.button1);
pickContact.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, 1);
}
});
}
else{
Toast.makeText(this, "select points", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
Uri uri = data.getData();
if (uri != null) {
Cursor c = null;
try {
c = getContentResolver().query(uri, new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE },
null, null, null);
if (c != null && c.moveToFirst()) {
String number = c.getString(0);
int type = c.getInt(1);
showSelectedNumber(type, number);
SmsManager.getDefault().sendTextMessage(number, null, String.valueOf(points), null, null);
}
} finally {
if (c != null) {
c.close();
}
}
}
}
}
public void showSelectedNumber(int type, String number) {
Toast.makeText(this, type + ": " + number, 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.main, menu);
return true;
}
}
UPDATE:
thats before enerting to the line when i get null ... I draw 4 polylines= 5 coordinates
05-12 15:57:21.410: I/System.out(7375): 0523123345
05-12 15:57:21.410: I/System.out(7375): [lat/lng: (32.84536764138551,35.070853158831596), lat/lng: (32.84437612923071,35.07208328694105), lat/lng: (32.844574432547816,35.07010214030743), lat/lng: (32.84338460599924,35.071389600634575), lat/lng: (32.843805159677125,35.069672986865044)]
You can see that the first line is the number and the seconds line is the points... it seems ok so how come im getting null ther ????