二进制XML文件行#15:错误膨胀类片段

时间:2013-08-14 15:25:27

标签: android google-maps

我有这个包含google maps v2的xml:

<LinearLayout 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:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Snapshot" />

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

和我的活动

public class display extends Activity {
    GoogleMap map;
    File dbFile;
    String first_lat,first_long;

    @SuppressLint("NewApi")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps_map);

        PolylineOptions line = new PolylineOptions();

        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();
        /*
         * Adatbázis
         */
        try {
            dbFile = getDatabasePath("/mnt/sdcard/Download/TeleSensors.db");
        } catch (Exception e) {

        }

        SQLiteDatabase myDataBase = SQLiteDatabase.openDatabase(
                dbFile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);

        Cursor cur_lat = myDataBase.rawQuery(
                "select * from GPS_Values where id = 1;", null);

        Integer count1 = 0;
        while (cur_lat.moveToNext()) {
            first_lat = cur_lat.getString(1);
            first_long = cur_lat.getString(2);
            count1++;
            Log.e("Elsok",
                    first_lat.toString() + " --- " + first_long.toString());
        }


        Cursor curTAB = myDataBase.rawQuery("SELECT * FROM  GPS_Values;", null);

        Integer count = 0;
        while (curTAB.moveToNext()) {
            String s_latitude = curTAB.getString(1);
            String s_longitude = curTAB.getString(2);
            count++;
            double latitude = Double.parseDouble(s_latitude);
            double longitude = Double.parseDouble(s_longitude);
            line.add(new LatLng(latitude, longitude));

            Log.i("Coordinates",
                    s_latitude.toString() + " --- " + s_longitude.toString());

        }
        curTAB.close();
        myDataBase.close();
        // adatbázis vége

        double latitude = Double.parseDouble(first_lat);
        double longitude = Double.parseDouble(first_long);

        map.addPolyline(line);
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15));
        map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);

        gomb_figyelo();

    }
    private void gomb_figyelo() {
        // TODO Auto-generated method stub
        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                SnapshotReadyCallback callback = new SnapshotReadyCallback() {
                    Bitmap bitmap;

                    public void onSnapshotReady(Bitmap snapshot) {
                        // TODO Auto-generated method stub
                        bitmap = snapshot;
                        try {
                            FileOutputStream out = new FileOutputStream(
                                    "/mnt/sdcard/Download/TeleSensors.png");
                            bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                            Toast.makeText(
                                    getApplicationContext(),
                                    "A képernyőkép kimentve: /mnt/sdcard/Download/TeleSensors.png",
                                    Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                };

                map.snapshot(callback);

            }
        });
    }
}

并收到此错误消息:

08-14 17:22:43.509: E/AndroidRuntime(13760): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eyecom.tools.telesensors/com.eyecom.tools.telesensors.display}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment

你帮助我,因为#15行只有片段

2 个答案:

答案 0 :(得分:4)

如果您运行的是API级别&lt; 11的代码,请使用FragmentActivity而不是扩展Activity并使用XML格式,使用"com.google.android.gms.maps.SupportMapFragment"

答案 1 :(得分:0)

您的问题低于3.0版本不支持碎片,但您正在使用。

解决方案:

1)set your minimumSDk="11" and run into 3.0 or above versions of device.
       or
2)Use SupportMapFragment instead of MapFragment and Add Support Library
into your project.

(Right click on your project -> Android Tools -> click Add Support Library)