1

Android「Google Maps Android API v2」のサンプルコードを動かそうとしています。プロジェクトがエラーなしでビルドされます。ただし、アプリを実行しようとすると、アプリがすぐにクラッシュします。

Java コード :

package com.example.Bardo;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;


public class GPS extends FragmentActivity{

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps);
       SupportMapFragment fragment = new SupportMapFragment();
       fragment.getFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();

    }


}

XML :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".GPS" >

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

</RelativeLayout>

logcat の出力:

08-29 09:31:37.286: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
08-29 09:31:44.396: E/Trace(1494): error opening trace file: No such file or directory (2)
08-29 09:31:44.466: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
08-29 09:31:46.397: E/dalvikvm(1494): Could not find class 'com.example.Bardo.GPS', referenced from method com.example.Bardo.Acceuil$5.onClick
08-29 09:31:46.536: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
08-29 09:35:13.466: E/ThrottleService(345): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)

マニフェスト:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.Bardo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk

        android:minSdkVersion="8"
        android:targetSdkVersion="17" />


    <permission
        android:name="com.example.Bardo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
     <uses-permission android:name="com.example.Bardo.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />



    <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_bardo"
        android:label="Bardo Museum"
        android:theme="@style/AppTheme" >



        <activity
            android:name=".Acceuil"
            android:label="Musée de la Bardo" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <activity android:name=".Objets" android:label="Objets">  </activity>
        <activity android:name=".GPS" android:label="GPS"> </activity>
        <activity android:name=".Detail" android:label="Detail"></activity>
        <activity
                android:name=".Galeries"
                android:label="Galeries"
               />
        <activity
                android:name=".Evennements"
                android:label="Evennements"/>
        <activity
                android:name=".Infos"
                android:label="Infos"/>

    </application>

</manifest> 

私はグーグルで検索しましたが、この例外に関する情報は見つかりませんでした。私はこの問題について本当に混乱しており、修正方法がわかりません。誰もそれを修正する方法を知っていますか? ありがとう。

4

3 に答える 3

3

このエラーがある場合error opening trace file: No such file or directory

コンピューターに minSdkVersion または targetSdkVersion をインストールしていないために発生します。私は今それをテストしました。

たとえば、Manifest.xml に次の行があるとします。

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

また、コンピューターに API17 のみをインストールすると、エラーが報告されます。テストする場合は、別の API バージョン (この場合は API 8) をインストールしてみてください。

そして、このエラーについてro.sf.lcd_density must be defined as a build property

メインスレッドでネットワークコードを使用していると思います。バックグラウンド スレッドでネットワーキングを行います。AsyncTask は良いオプションです。

これらは両方ともあなたの問題を解決するはずです。

于 2013-08-29T09:52:40.610 に答える
2

Maps API キーがありません。このドキュメントに従って、すべてを正しく設定してください: https://developers.google.com/maps/documentation/android/start

于 2013-08-29T09:51:50.370 に答える
0

クラスの冒頭でパッケージ名を確認してください。アプリケーションの名前と一致する必要があります。これはある種のコピペエラーかもしれません

于 2013-08-29T09:52:19.963 に答える