Guest User

Untitled

a guest
Oct 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. i am getting the null pointer Exception at ViewRoot.Draw(boolean) in android.how to solve this?
  2.  
  3. here is my code
  4.  
  5.  
  6. LayoutInflater li= LayoutInflater.from(this);
  7. View textEntryView = li.inflate(R.layout.alertbox, null);
  8.  
  9. final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
  10. dialog.setTitle("Enter the places");
  11. dialog.setView(textEntryView);
  12.  
  13. splc = (EditText) textEntryView.findViewById(R.id.strtplace);
  14. dialog.setPositiveButton("Ok", new OnClickListener(){
  15.  
  16. @Override
  17. public void onClick(DialogInterface dialog, int which) {
  18. // TODO Auto-generated method stub
  19. pd = ProgressDialog.show(TravellogActivity.this, "Working..", "Searching your address", true, false);
  20. //Show a progress dialog
  21.  
  22.  
  23. searchAdress = new Thread(){
  24. public void run(){
  25. String addressInput = splc.getText().toString(); // Get input text
  26. try {
  27. foundAdresses = gc.getFromLocationName(addressInput, 5); // Search addresses
  28. Thread.sleep(1500);
  29. } catch (Exception e) {
  30. // @todo: Show error message
  31. }
  32. showAdressResults.sendEmptyMessage(0);
  33. }
  34. };
  35. searchAdress.start();
  36.  
  37. }
  38. });
  39.  
  40.  
  41.  
  42.  
  43. private Handler showAdressResults = new Handler() {
  44. @Override
  45. public void handleMessage(Message msg) {
  46. pd.dismiss();
  47.  
  48. if (foundAdresses.size() == 0) { // if no address found,
  49. // display an error
  50. //
  51. // p = new GeoPoint((int) (foundAdresses.get(0).getLatitude() * 1E6),
  52. // (int) (foundAdresses.get(0).getLongitude() * 1E6));
  53. //
  54. //
  55. Dialog locationError = new AlertDialog.Builder(
  56. TravellogActivity.this).setIcon(0).setTitle(
  57. "Error").setPositiveButton(R.string.ok, null)
  58. .setMessage(
  59. "Sorry, your address doesn't exist.")
  60. .create();
  61. locationError.show();
  62.  
  63. } else { // else display address on map
  64. for (int i = 0; i < foundAdresses.size(); ++i) {
  65. // Save results as Longitude and Latitude
  66. // @todo: if more than one result, then show a
  67. // select-list
  68. Address x = foundAdresses.get(i);
  69. latit = x.getLatitude();
  70. longi = x.getLongitude();
  71. }
  72. navigateToLocation((latit * 1000000), (longi * 1000000),myMapView); // display the found address
  73. };
  74.  
  75. return ;
  76.  
  77. }
  78.  
  79. private void navigateToLocation(double latitude, double longitude,
  80. MapView myMapView) {
  81. // TODO Auto-generated method stub
  82. p = new GeoPoint((int) (foundAdresses.get(0).getLatitude() * 1E6),
  83. (int) (foundAdresses.get(0).getLongitude() * 1E6));
  84. MC.animateTo(p);
  85.  
  86. myMapView.invalidate();
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. protected class MyLocationOverlay extends com.google.android.maps.Overlay {
  96.  
  97. @Override
  98. public boolean draw(Canvas canvas, MapView myMapView, boolean shadow, long when) {
  99. Paint paint = new Paint();
  100.  
  101. super.draw(canvas, myMapView, shadow);
  102. // Converts lat/lng-Point to OUR coordinates on the screen.
  103. Point myScreenCoords = new Point();
  104. myMapView.getProjection().toPixels(p, myScreenCoords);
  105.  
  106.  
  107.  
  108.  
  109.  
  110. paint.setStrokeWidth(1);
  111. paint.setARGB(255, 255, 255, 255);
  112. paint.setStyle(Paint.Style.STROKE);
  113.  
  114. Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
  115.  
  116. canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
  117. canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);
Add Comment
Please, Sign In to add comment