Bilel
Bilel

Reputation: 25

Google Maps Android API v2 application crashing

I'm trying to get the sample code of Android 'Google Maps Android API v2' working. I get the project built without errors. However, when I try to run the app , the app crashes immediately.

Java Code :

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();

    }


}

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

The logcat output:

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)

The Manifest:

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

I googled and found no information about this exception. I'm really confused about this problem and don't know how to fix it. Does anyone have idea how to fix it? Thanks.

Upvotes: 1

Views: 2136

Answers (3)

Niko
Niko

Reputation: 1377

If you have this error error opening trace file: No such file or directory

It happens because you haven't installed the minSdkVersion or targetSdkVersion in your computer. I've tested it right now.

For example, if you have those lines in your Manifest.xml:

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

And you have installed only the API17 in your computer, it will report you an error. If you want to test it, try installing the other API version (in this case, API 8).

And for this error ro.sf.lcd_density must be defined as a build property

I think You are using networking code on the main thread. Do networking in a background thread. AsyncTask is a good option.

Both these should solve your problem.

Upvotes: 2

user2357448
user2357448

Reputation:

Check your package names in the beginning of your class. They should match the name of your Application. This might be some kind of copy paste error

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75635

You do not have Maps API key. Follow this document to set all up correctly: https://developers.google.com/maps/documentation/android/start

Upvotes: 1

Related Questions