2016-04-03 75 views
-3

我findViewById拋出錯誤,說它還沒有被定義,它要求我創建一個函數。我該怎麼辦?我findViewByID thowing錯誤?

public void geoLocate(View v) throws IOException { 
    hideSoftKeyboard(v); 
    EditText et = (EditText) findViewById(R.id.editText1); 
    String location = et.getText().toString(); 
    Geocoder gc = new Geocoder(context); 
    List<Address> list = gc.getFromLocationName(location, 1); 
    Address add = list.get(0); 
    String locality = add.getLocality(); 
    Toast.makeText(context, locality, Toast.LENGTH_LONG).show(); 
    double lat = add.getLatitude(); 
    double lng = add.getLatitude(); 
    gotoLocation(lat, lng, DEFAULTZOOM); 
    MarkerOptions markerOptions = new MarkerOptions().title(locality).position(new LatLng(lat,lng)); 
    mMap.addMarker(markerOptions); 


} 
+2

安置自己的logcat錯誤 –

+1

什麼課這是什麼? –

+1

這個方法在'Activity'裏面嗎? – PPartisan

回答

0

在你的函數查找用戶喜歡這個

EditText et = (EditText) v.findViewById(R.id.editText1); 

您havve使用該方法通過查看變量來查找ID

+4

這隻有在editText1是View v。 – RamIndani

+0

的一部分時纔有效,如果不是,那麼在尋找id時應該沒有錯誤 –

+0

@RamIndani可以理解editext是查看的一部分 –