我的应用程序加载谷歌地图,用户正在绘制多段线...在他完成应用程序发送他的坐标,他从他的联系人列表中选择另一个Android设备...现在问题是,当他绘制当他按下发送按钮时,应用程序崩溃并且没有发送短信...超过3折线...应用程序工作直到3折线.. 那就是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
那就是主要的:
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;
}
}
更新:
那是在我获得null之前在线路上的那个...我画了4条折线= 5个坐标
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)]
你可以看到第一行是数字,而秒行就是点...看起来好了所以我怎么会得到空的????
答案 0 :(得分:1)
好吧我刚刚找到答案......:当SMS消息超出大小限制时,SmsManager.sendTextMessage()抛出NullPointerException。即最大字符限制为159
很伤心。