简体   繁体   English

应用已停止工作-片段布局-Google Maps API v2

[英]App stopped working - Fragment layout - Google Maps API v2

I saw a lot of questions on stack overflow and no answer solved my problem, i tried to set a layout to the fragment and the app stops working again and again, i tried too many different templates for the fragment to be in relative layout and to be on it's own without relative layout and nothing happens but stops. 我在堆栈溢出上看到了很多问题,没有答案解决了我的问题,我尝试为片段设置布局,应用程序一次又一次停止工作,我尝试了太多不同的模板来使片段处于相对布局和没有相对布局就靠它自己,什么也不会发生,只是停下来。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:map="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
  android:layout_height="match_parent"
 tools:context=".MainActivity" >
<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />
 </RelativeLayout> 

when i replace the fragment with a textview or button the app works, thank you very much. 当我用textview或button替换片段时,该应用程序有效,非常感谢。

logCat logCat

    07-06 05:44:00.002: ERROR/CellLocation(630): create GsmCellLocation
07-06 05:44:00.002: ERROR/CellLocation(13659): create GsmCellLocation
07-06 05:44:00.011: ERROR/CellLocation(15213): create GsmCellLocation
07-06 05:44:00.012: ERROR/CellLocation(13659): create GsmCellLocation
07-06 05:44:00.014: ERROR/CellLocation(15213): create GsmCellLocation
07-06 05:44:00.030: ERROR/FWKEXT(630): Enter GetCurrentOP
07-06 05:44:00.066: ERROR/CellLocation(13659): create GsmCellLocation
07-06 05:44:00.097: ERROR/SQLiteLog(22227): (257) Open fd: 69, file: /data/data/com.htc.weather.service/databases/weather.db-journal
07-06 05:44:00.098: ERROR/SQLiteLog(22227): (257) Close fd: 69
07-06 05:44:00.113: ERROR/SQLiteLog(22227): (257) Open fd: 69, file: /data/data/com.htc.weather.service/databases/weathersync.db-journal
07-06 05:44:00.116: ERROR/SQLiteLog(22227): (257) Close fd: 69
07-06 05:44:00.136: ERROR/SQLiteLog(22227): (257) Open fd: 69, file: /data/data/com.htc.weather.service/databases/weathersync.db-journal
07-06 05:44:00.136: ERROR/SQLiteLog(22227): (257) Close fd: 69
07-06 05:44:00.138: ERROR/SQLiteLog(22227): (257) Open fd: 68, file: /data/data/com.htc.weather.service/databases/weathersync.db-journal
07-06 05:44:00.138: ERROR/SQLiteLog(22227): (257) Close fd: 68
07-06 05:44:00.139: ERROR/SQLiteLog(22227): (257) Open fd: 68, file: /data/data/com.htc.weather.service/databases/weathersync.db-journal
07-06 05:44:00.159: ERROR/SQLiteLog(22227): (257) Close fd: 68
07-06 05:44:00.160: ERROR/FWKEXT(630): Enter GetCurrentOP
07-06 05:44:00.176: ERROR/SQLiteLog(22227): (257) Open fd: 69, file: /data/data/com.htc.weather.service/databases/weather.db-journal
07-06 05:44:00.176: ERROR/SQLiteLog(22227): (257) Close fd: 69
07-06 05:44:03.437: ERROR/CellLocation(630): create GsmCellLocation
07-06 05:44:03.439: ERROR/CellLocation(630): create GsmCellLocation
07-06 05:44:03.444: ERROR/CellLocation(13659): create GsmCellLocation
07-06 05:44:03.445: ERROR/CellLocation(15213): create GsmCellLocation
07-06 05:44:03.459: ERROR/CellLocation(15213): create GsmCellLocation
07-06 05:44:03.475: ERROR/CellLocation(13659): create GsmCellLocation
07-06 05:44:03.491: ERROR/CellLocation(13659): create GsmCellLocation
07-06 05:44:06.426: ERROR/BatteryService(630): Enter GetStatus success
07-06 05:44:06.427: ERROR/BatteryService(630): ioctl ok: 323
07-06 05:44:06.449: ERROR/BatteryService(630): Enter GetStatus success
07-06 05:44:06.450: ERROR/BatteryService(630): ioctl ok: 323
07-06 05:44:06.452: ERROR/BatteryService(630): Enter GetStatus success
07-06 05:44:06.453: ERROR/BatteryService(630): ioctl ok: 323
07-06 05:44:13.007: ERROR/Sensors(630): new acc setDelay handle(4),ns(100000000) err! go to hwmsen
07-06 05:44:13.484: ERROR/SQLiteLog(29957): (257) Open fd: 85, file: /data/data/com.avast.android.mobilesecurity/databases/avast.db-journal
07-06 05:44:13.485: ERROR/SQLiteLog(29957): (257) Close fd: 85
07-06 05:44:13.493: ERROR/SQLiteLog(29957): (257) Open fd: 85, file: /data/data/com.avast.android.mobilesecurity/databases/avast.db-journal
07-06 05:44:13.493: ERROR/SQLiteLog(29957): (257) Close fd: 85
07-06 05:44:13.862: ERROR/SQLiteLog(25946): (257) Open fd: 81, file: /data/data/com.facebook.orca/databases/prefs_db-journal
07-06 05:44:13.864: ERROR/SQLiteLog(25946): (257) Close fd: 81
07-06 05:44:13.866: ERROR/SQLiteLog(25946): (257) Open fd: 81, file: /data/data/com.facebook.orca/databases/prefs_db-journal
07-06 05:44:13.887: ERROR/SQLiteLog(25946): (257) Close fd: 81
07-06 05:44:16.425: ERROR/BatteryService(630): Enter GetStatus success
07-06 05:44:16.425: ERROR/BatteryService(630): ioctl ok: 323
07-06 05:44:16.426: ERROR/BatteryService(630): Enter GetStatus success
07-06 05:44:16.426: ERROR/BatteryService(630): ioctl ok: 323
07-06 05:44:16.427: ERROR/BatteryService(630): Enter GetStatus success
07-06 05:44:16.427: ERROR/BatteryService(630): ioctl ok: 323
07-06 05:44:18.388: ERROR/SQLiteLog(790): (257) Open fd: 121, file: /data/data/com.android.providers.telephony/databases/mmssms.db-journal
07-06 05:44:18.390: ERROR/SQLiteLog(790): (257) Close fd: 121
07-06 05:44:18.406: ERROR/SQLiteLog(790): (257) Open fd: 121, file: /data/data/com.android.providers.telephony/databases/mmssms.db-journal
07-06 05:44:18.406: ERROR/SQLiteLog(790): (257) Close fd: 121
07-06 05:44:23.628: ERROR/Sensors(630): new acc setDelay handle(4),ns(200000000) err! go to hwmsen
07-06 05:44:23.628: ERROR/Sensors(630): new acc setDelay handle(4),ns(100000000) err! go to hwmsen
07-06 05:44:23.645: ERROR/KeyguardUpdateMonitor(630): Object tried to add another callback
07-06 05:44:23.645: ERROR/KeyguardUpdateMonitor(630): java.lang.Exception: Called by
07-06 05:44:23.645: ERROR/KeyguardUpdateMonitor(630):     at com.android.internal.policy.impl.keyguard.KeyguardUpdateMonitor.registerCallback(KeyguardUpdateMonitor.java:1118)
07-06 05:44:23.645: ERROR/KeyguardUpdateMonitor(630):     at com.android.internal.policy.impl.keyguard.KeyguardSelectorView.onResume(KeyguardSelectorView.java:338)
07-06 05:44:23.645: ERROR/KeyguardUpdateMonitor(630):     at com.android.internal.policy.impl.keyguard.KeyguardHostView.onScreenTurnedOn(KeyguardHostView.java:1158)
07-06 05:44:23.645: ERROR/KeyguardUpdateMonitor(630):     at com.android.internal.policy.impl.keyguard.KeyguardViewManager.onScreenTurnedOn(KeyguardViewManager.java:406)
07-06 05:44:23.645: ERROR/KeyguardUpdateMonitor(630):     at com.android.internal.policy.impl.keyguard.KeyguardViewMediator.handleNotif

Here's my java code, the app stops when i hash the map code too, i believe it's something in the layout. 这是我的Java代码,当我也对地图代码进行哈希处理时,该应用程序就会停止,我认为这是布局中的内容。

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {
      static final LatLng HAMBURG = new LatLng(53.558, 9.927);
      static final LatLng KIEL = new LatLng(53.551, 9.993);
      private GoogleMap map;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();

        if (map!=null){
          Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
              .title("Hamburg"));
          Marker kiel = map.addMarker(new MarkerOptions()
              .position(KIEL)
              .title("Kiel")
              .snippet("Kiel is cool")
              .icon(BitmapDescriptorFactory
                  .fromResource(R.drawable.ic_launcher)));
        }

      } 
}

Please post the log as it is not clear from your question. 请张贴日志,因为您的问题尚不清楚。
One possible mistake can be => You are using MapFragment which extends Fragment . 一个可能的错误可能是=>您正在使用MapFragment扩展Fragment Try using SupportMapFragment. 尝试使用SupportMapFragment。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM