我的MapActive在低API手机上崩溃了。在我的LG G4上没有崩溃。为什么会这样?
这是我的代码:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private static final String FIREBASE_URL="https://***.firebaseio.com/";
private Firebase firebaseRef;
private LocationManager locationManager;
private GoogleMap mMap;
boolean bPermissionGranted;
public static final int MY_PERMISSIONS_REQUEST_LOCATION = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps2);
Firebase.setAndroidContext(this);
firebaseRef = new Firebase(FIREBASE_URL);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
setUpMapIfNeeded();
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
final String title = marker.getTitle().toString();
firebaseRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot user : dataSnapshot.child("users").getChildren()) {
if (user.child("event/event_title").exists()) {
String event_title = user.child("event/event_title").getValue().toString();
if (title.equals(event_title)) {
String event_date = user.child("event/event_date").getValue().toString();
String event_content = user.child("event/event_content").getValue().toString();
String age_limit = user.child("event/age_limit").getValue().toString();
String event_hour = user.child("event/event_hour").getValue().toString();
String location_left = user.child("location_left").getValue().toString();
String location_right = user.child("location_right").getValue().toString();
String event_address=user.child("event_address").getValue().toString();
String club_name=user.child("club_name").getValue().toString();
final SharedPreferences sp = getSharedPreferences("key", 0);
final SharedPreferences.Editor sedt = sp.edit();
sedt.putString("event_address",event_address);
sedt.putString("event_title", event_title);
sedt.putString("event_date", event_date);
sedt.putString("event_content", event_content);
sedt.putString("age_limit", age_limit);
sedt.putString("event_hour", event_hour);
sedt.putString("location_left", location_left);
sedt.putString("location_right", location_right);
sedt.putString("club_name",club_name);
sedt.commit();
}
}
}
Intent intent = new Intent(MapsActivity.this, eventInfo.class);
startActivity(intent);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(MapsActivity.this, "Error", Toast.LENGTH_LONG).show();
}
});
return true;
}
});
}
private void setUpMapIfNeeded() {
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
Log.w("myApp", "1");
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
Log.w("myApp", "2");
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(32.065483, 34.824550));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(10);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
}
}
}
@Override
public void onMapReady(final GoogleMap googleMap) {
mMap=googleMap;
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
}
else
{
Log.w("myApp", "3");
mMap.setMyLocationEnabled(true);
}
firebaseRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.w("myApp", "4");
for (DataSnapshot child : dataSnapshot.child("users").getChildren()) {
if(child.child("event/event_title").exists()) {
if (dateRelevant(child.child("event/event_date").getValue().toString()) == true) {
String rightLocation = child.child("location_right").getValue().toString();
String leftLocation = child.child("location_left").getValue().toString();
double location_left = Double.parseDouble(leftLocation);
double location_right = Double.parseDouble(rightLocation);
String event_title = child.child("event/event_title").getValue().toString();
LatLng cod = new LatLng(location_left, location_right);
googleMap.addMarker(new MarkerOptions().position(cod).title(event_title));
}
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
public boolean dateRelevant(String event_date) {
Calendar now = Calendar.getInstance();
int curr_year = now.get(Calendar.YEAR);
int curr_month = now.get(Calendar.MONTH) + 1; // Note: zero based!
int curr_day = now.get(Calendar.DAY_OF_MONTH);
String curr_year2=curr_year+"";
String [] esre = curr_year2.split("0");
int esreYear=Integer.parseInt(esre[1]);
int day;
int month;
int year;
if(event_date.indexOf(".")!=-1) {
String[] dateParts = event_date.split("\\.");
day = Integer.parseInt(dateParts[0]);
month = Integer.parseInt(dateParts[1]);
year = Integer.parseInt(dateParts[2]);
}
else
{
String[] dateParts = event_date.split("/");
day = Integer.parseInt(dateParts[0]);
month = Integer.parseInt(dateParts[1]);
year = Integer.parseInt(dateParts[2]);
}
if(year<esreYear||(curr_year>year&&year!=16&&year!=17)) {
return false;
}
else
{
if(year==curr_year||year==esreYear)
{
if(month==curr_month)
{
if(day>=curr_day)
{
return true;
}
else
{
return false;
}
}
else
{
if(month>curr_month)
{
return true;
}
else
{
return false;
}
}
}
else
{
if(esreYear<year||curr_year<year)
{
return true;
}
else {
return false;
}
}
}
}
}
日志中的错误显示:
致命异常:主进程:com.giladneiger.clubber,PID:22389java.lang.运行时异常:无法启动活动组件信息{com.giladneiger.clubber/com.giladneiger.clubber.MapsActivity}:java.lang.android.app.ActivityThread.perform启动活动(ActivityThread.java:2252)
您正在使用OnMapReadyCallback
,但您正在onCreate
上设置地图。如果地图尚未准备好,您将收到一个NullPointerexception
。
将所有初始化代码移动到onMap就绪
方法。
你的代码应该是这样的:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps2);
Firebase.setAndroidContext(this);
firebaseRef = new Firebase(FIREBASE_URL);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
// Remove the setUpMapIfNeeded method
@Override
public void onMapReady(final GoogleMap googleMap) {
mMap=googleMap;
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(32.065483, 34.824550));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(10);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
// ...
});
// ...
}
我面临的一些问题,没有收到通知在一些电话。我也不接受GCM的意图。这是我打电话给GCM注册时的日志。在像Nexus和Moto这样的手机上,它运行得非常好。但在Lava和Karbonn这样的低端手机上,我就面临着这个问题。 D/PowerManagerService(649):AcquireWakeLockInternal:lock=1114432392,Flags=0x1,tag=“gcm_con
我在一个片段中遇到了一个问题,该片段从新的Google Maps API中嵌入了SuportMapFragment。当创建我的片段时,它从方法开始,在中获取一些数据。当这种情况发生时,MapFragment保持在屏幕外,而是显示进度条。 完成后,我向MapView的事件注册。然后我显示片段,这导致地图视图被显示和布局。被触发,动画开始。 多谢!
问题内容: 我正在学习amd64汇编程序,并尝试实现一个简单的Unix过滤器。由于未知的原因,甚至简化为最低版本(下面的代码),它也会随机崩溃。 我试图在GNU调试器(gdb)中调试该程序。在gdb的默认配置下,该程序运行良好,但是如果启用地址随机化(),该程序将开始崩溃(SIGSEGV)。清单中标记了有问题的说明: 该程序旨在从stdin读取最多64kB的数据,将其存储到堆栈中的缓冲区中,将读取
我第一次试着用docker。我需要它使selenium在服务器上运行。所以我可以把这个脚本放到任何一台服务器上,这样就可以毫不费力地工作了。但是突然间它就不起作用了,它就不起作用了。我试着在谷歌上搜索,但什么都没有。现在我在这里寻求帮助。也许我错过了什么,也许我把事情搞砸了,现在我看到了解决办法。解决方案是下载chromedriver,拒绝独立运行selenium。 开始硒 Dockerfile去
在我的应用程序中,我已经授予了的权限,并且它正在顺利地检测接收/offhook/idle统计信息。 更新 这是Logcat错误: 04-26 04:55:04.422 140 6-2091/?W/Audio_HW_Generic:没有向哈尔提供足够的数据,预期位置为1097356,只写了1097280 04-26 04:55:04.434 506 5-5065/?d/AndroidRuntime: