Getters 在调用另一个 class 后返回 null
Getters returning null after calling in another class
我想使用 getter 和 setter 获得另一个 class 的标记纬度。但吸气剂总是 return 空值。这对我来说完全没有意义。我正在努力找出这里出了什么问题。
这是我的位置 1 class
我在哪里使用二传手
public class Location1 extends AppCompatActivity implements OnMapReadyCallback {
//do changes inside loaded map
@Override
public void onMapReady(GoogleMap googleMap) {
Toast.makeText(Location1.this, "Map Is Ready", Toast.LENGTH_SHORT).show();
Log.d(TAG, "onMapReady: map is ready");
mMap = googleMap;
if (permission_Granted) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.getUiSettings().setCompassEnabled(true);
//Afer Clicking google map marker info window
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
//Here using setters
marker1 marker1 = new marker1();
marker1.setMarkerLat(marker.getPosition().latitude);
Toast.makeText(Location1.this,String.valueOf(marker.getPosition().latitude),Toast.LENGTH_SHORT).show();
startActivity(new Intent(Location1.this, pop.class));
}
});
}
}
和我的标记 1 class
public class marker1 {
Double markerLat;
public Double getMarkerLat() {
return markerLat;
}
public void setMarkerLat(Double markerLat) {
this.markerLat = markerLat;
}
}
并弹出 class
我在哪里使用 return 空值
的 Getters
public class pop extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.garagepopup_1);
GarageNameTextView = (TextView) findViewById(R.id.nameView);
GarageAddrTextView = (TextView) findViewById(R.id.addresView);
GarageContactTextView = (TextView) findViewById(R.id.phoneView);
dbGarages= FirebaseDatabase.getInstance().getReference("Garages");
//Using getters
marker1 marker1 = new marker1();
String lat=String.valueOf(marker1.getMarkerLat());
Toast.makeText(pop.this,lat, Toast.LENGTH_SHORT).show();
}
}
我被困在这里了。无法继续前进..任何帮助将不胜感激..
谢谢
@Kasun_Chamara 获取第二个位置 activity 你有一些方法:
第一:
您必须将 markerLat
设置为静态字段。
像这样:
public class marker1 {
static Double markerLat;
public Double getMarkerLat() {
return markerLat;
}
public void setMarkerLat(Double markerLat) {
this.markerLat = markerLat;
}
}
秒:
使用 putExtra 发送位置参数:
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
//Here using setters
marker1 marker1 = new marker1();
marker1.setMarkerLat(marker.getPosition().latitude);
Toast.makeText(Location1.this,String.valueOf(marker.getPosition().latitude),Toast.LENGTH_SHORT).show();
Intent myintent = new Intent(Location1.this, pop.class);
myintent.putExtra("Location",marker.getPosition().latitude);
startActivity(myintent);
}
});
秒Activity:
getIntent().getIntExtra("Location",0);
第三个:
根据@skandigraun 的说法,您可以发送它的对象:
How to pass an object from one activity to another on Android
我想使用 getter 和 setter 获得另一个 class 的标记纬度。但吸气剂总是 return 空值。这对我来说完全没有意义。我正在努力找出这里出了什么问题。
这是我的位置 1 class 我在哪里使用二传手
public class Location1 extends AppCompatActivity implements OnMapReadyCallback {
//do changes inside loaded map
@Override
public void onMapReady(GoogleMap googleMap) {
Toast.makeText(Location1.this, "Map Is Ready", Toast.LENGTH_SHORT).show();
Log.d(TAG, "onMapReady: map is ready");
mMap = googleMap;
if (permission_Granted) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.getUiSettings().setCompassEnabled(true);
//Afer Clicking google map marker info window
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
//Here using setters
marker1 marker1 = new marker1();
marker1.setMarkerLat(marker.getPosition().latitude);
Toast.makeText(Location1.this,String.valueOf(marker.getPosition().latitude),Toast.LENGTH_SHORT).show();
startActivity(new Intent(Location1.this, pop.class));
}
});
}
}
和我的标记 1 class
public class marker1 {
Double markerLat;
public Double getMarkerLat() {
return markerLat;
}
public void setMarkerLat(Double markerLat) {
this.markerLat = markerLat;
}
}
并弹出 class 我在哪里使用 return 空值
的 Getterspublic class pop extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.garagepopup_1);
GarageNameTextView = (TextView) findViewById(R.id.nameView);
GarageAddrTextView = (TextView) findViewById(R.id.addresView);
GarageContactTextView = (TextView) findViewById(R.id.phoneView);
dbGarages= FirebaseDatabase.getInstance().getReference("Garages");
//Using getters
marker1 marker1 = new marker1();
String lat=String.valueOf(marker1.getMarkerLat());
Toast.makeText(pop.this,lat, Toast.LENGTH_SHORT).show();
}
}
我被困在这里了。无法继续前进..任何帮助将不胜感激.. 谢谢
@Kasun_Chamara 获取第二个位置 activity 你有一些方法:
第一:
您必须将 markerLat
设置为静态字段。
像这样:
public class marker1 {
static Double markerLat;
public Double getMarkerLat() {
return markerLat;
}
public void setMarkerLat(Double markerLat) {
this.markerLat = markerLat;
}
}
秒: 使用 putExtra 发送位置参数:
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
//Here using setters
marker1 marker1 = new marker1();
marker1.setMarkerLat(marker.getPosition().latitude);
Toast.makeText(Location1.this,String.valueOf(marker.getPosition().latitude),Toast.LENGTH_SHORT).show();
Intent myintent = new Intent(Location1.this, pop.class);
myintent.putExtra("Location",marker.getPosition().latitude);
startActivity(myintent);
}
});
秒Activity:
getIntent().getIntExtra("Location",0);
第三个:
根据@skandigraun 的说法,您可以发送它的对象:
How to pass an object from one activity to another on Android