2013-01-26 4 views
0

내 토스트에서 내 데이터를 볼 수없는 이유는 무엇입니까 ?? 앱을 실행할 때마다 충돌이 발생합니다. 하지만 토스트를 지우면 부드럽게 돌아갑니다.Android : 토스트 내 데이터보기.

{com.example.test/com.example.test.PinPoints}: java.lang.NullPointerException 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.ActivityThread.access$600(ActivityThread.java:140) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.os.Handler.dispatchMessage(Handler.java:99) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.os.Looper.loop(Looper.java:137) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.ActivityThread.main(ActivityThread.java:4898) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at java.lang.reflect.Method.invokeNative(Native Method) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at java.lang.reflect.Method.invoke(Method.java:511) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at dalvik.system.NativeStart.main(Native Method) 
01-26 02:27:17.900: E/AndroidRuntime(19389): Caused by: java.lang.NullPointerException 
01-26 02:27:17.900: E/AndroidRuntime(19389): at com.example.test.PinPoints.onCreate(PinPoints.java:31) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.Activity.performCreate(Activity.java:5206) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
01-26 02:27:17.900: E/AndroidRuntime(19389): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 
01-26 02:27:17.900: E/AndroidRuntime(19389): ... 11 more 
:

이 ... 나는 모든 관련이없는 코드

GoogleMaps Class. 

    public class GoogleMaps extends MapActivity implements LocationListener { 



    public void addLocation() { 
     AlertDialog.Builder alert = new AlertDialog.Builder(this); 
     final EditText input = new EditText(this); 
     alert.setTitle("What do you want to call the location?"); 
     alert.setView(input); 
     alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int whichButton) { 

       value = input.getText().toString().trim(); 
       checklocationTitle(); 
      } 
     }); 

     alert.setNegativeButton("Cancel", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 
         dialog.cancel(); 
        } 
       }); 
     alert.show(); 
    } 


    public void checklocationTitle() { 
     if (value.length() > 3) { 
      Toast.makeText(this, "Name of the locations is know " + value, 
        Toast.LENGTH_LONG).show(); 
      try { 
       markedpinpoint = true; 
       midllat = touchedPoint.getLatitudeE6()/1E6; 
       midlongi = touchedPoint.getLongitudeE6()/1E6; 
       Geocoder geocoder = new Geocoder(getBaseContext(), 
         Locale.getDefault()); 
       List<Address> adress = geocoder.getFromLocation(
         touchedPoint.getLatitudeE6()/1E6, 
         touchedPoint.getLongitudeE6()/1E6, 1); 
       if (adress.size() > 0) { 
        String display = ""; 
        for (int i = 0; i < adress.get(0).getMaxAddressLineIndex(); i++) { 
         display += adress.get(0).getAddressLine(i) + "\n"; 
         OverlayItem overlayitem = new OverlayItem(touchedPoint, 
           value, display); 
         custom = new Location_Service(d, GoogleMaps.this); 
         custom.insertLocation(overlayitem); 
         overlayList.add(custom); 
        } 
       } else { 
        Toast.makeText(
          this, 
          "There where a problem to locate the selected adresse", 
          Toast.LENGTH_LONG).show(); 
       } 
      } catch (IOException e) { 
      } 
     } else { 
      Toast.makeText(this, 
        "Please provide a least 3 cifre Title for your location.", 
        Toast.LENGTH_LONG).show(); 
      addLocation(); 
     } 
    } 


    public void buttonLocations(View view) { 
     // stopLocationListner(); 
     // stopBackgroundService(); 
     Intent intent = new Intent(this, PinPoints.class); 
     startActivity(intent); 
     // Toast.makeText(this, "Gemte steder: " + custom.size(), 
     // Toast.LENGTH_LONG).show(); 

    } 
} 

    public class Location_Service extends ItemizedOverlay<OverlayItem> { 

     public ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>(); 

     public Location_Service(Drawable defaultMarker) { 
      super(boundCenter(defaultMarker)); 
      // TODO Auto-generated constructor stub 
     } 

     public ArrayList<Locations> getData() { 
      Locations hej = new Locations(); 
      ArrayList<Locations> tt = new ArrayList<Locations>(); 
      for (OverlayItem test : pinpoints) { 
       hej.setAdress(test.getSnippet()); 
       hej.setMidlat(test.getPoint().getLatitudeE6()); 
       hej.setMidlong(test.getPoint().getLongitudeE6()); 
       hej.setTitle(test.getTitle()); 
       tt.add(hej); 
      } 
      return tt; 
     } 

     public Location_Service(Drawable m, Context context) { 
      this(m); 
     } 

     @Override 
     protected OverlayItem createItem(int i) { 
      return pinpoints.get(i); 
     } 

     @Override 
     public int size() { 
      return pinpoints.size(); 
     } 

     public void insertLocation(OverlayItem item) { 
      pinpoints.add(item); 
      this.populate(); 
     } 

    } 


public class Locations { 
    int midlat; 
    int midlong; 
    String title; 
    String adress; 
    String distance; 

    public Locations(String title, String adress, String distance) { 
     super(); 
     this.title = title; 
     this.adress = adress; 
     this.distance = distance; 
    } 

    public Locations() { 

    } 

    public int getMidlat() { 
     return midlat; 
    } 

    public String getDistance() { 
     return distance; 
    } 

    public void setDistance(String distance) { 
     this.distance = distance; 
    } 

    public void setMidlat(int i) { 
     this.midlat = i; 
    } 

    public int getMidlong() { 
     return midlong; 
    } 

    public void setMidlong(int midlong) { 
     this.midlong = midlong; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getAdress() { 
     return adress; 
    } 

    public void setAdress(String adress) { 
     this.adress = adress; 
    } 

    @Override 
    public String toString() { 
     // TODO Auto-generated method stub 
     return title + adress + distance; 
    } 

} 

문제는 토스트 여기에서 발생 스트립이 지금까지

public class PinPoints extends Activity 

{ 

    private ListView lv; 
    private LocationsAdapter adapter; 
    private Location_Service locationss; 
    private ArrayList<Locations> fetch = new ArrayList<Locations>(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.locations); 

     Toast.makeText(this, 
       "Places: " + locationss.getData(), 
       Toast.LENGTH_LONG).show(); 

     for (int i = 0; i < 5; i++) { 

      Locations t = new Locations("Home", "Edvard", "2200m"); 

      fetch.add(t); 
     } 

     lv = (ListView) findViewById(R.id.listView1); 

     adapter = new LocationsAdapter(PinPoints.this, R.id.listView1, fetch); 
     lv.setAdapter(adapter); 

    } 
} 

이 mylog 파일 내 코드입니다

답변

1

위치는 onCreate에서 초기화되지 않으므로 널 포인터로 예외가 발생합니다.

+0

onCreate에서 위치를 어떻게 초기화 하시겠습니까? – Zaz

+0

나는 당신이 달성하고자하는 것을 모르지만 location = new Location_Service (// 당신의 드로어 블을 여기에 넣으십시오); onCreate에 전화하십시오 – fedepaol

+0

내 목표는 arraylist에서 더 많은 객체를 얻는 것입니다. 그래서 저는 나중에 토스트 성명서에 그것들을 모두 볼 수 있습니다. – Zaz

0

크래시 덤프를 보지 않고도 추측 게임은 아닙니다. 토스트에 표시 할 데이터를 얻으려고하면 locationssnull이라고 생각합니다. 따라서 locationss.getData()에 전화하면 NullReferenceException이 발생합니다.

+0

방금 ​​내 로그를 추가했습니다 : / – Zaz