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

时间:2015-07-06 03:21:38

标签: java android xml google-maps android-fragments

我看到很多关于堆栈溢出的问题,没有答案解决了我的问题,我试图设置一个布局到片段,应用程序一次又一次地停止工作,我尝试了太多不同的模板,使片段在相对布局,并在没有相对布局的情况下独立,没有任何事情发生,但停止。

 <?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> 

当我用文本视图或按钮替换片段时,应用程序正常工作,非常感谢。

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

这是我的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)));
        }

      } 
}

1 个答案:

答案 0 :(得分:0)

请发布日志,因为您的问题不明确 一个可能的错误可能是=&gt;您正在使用扩展MapFragmentFragment。尝试使用SupportMapFragment.