• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps MapView not working

joyu12

Lurker
Hi, i am trying to do the Google Map View tutorial, and i have followed it very precisly, but the app crashes each time on startup. Anyone who can help me?
Code:
Code:
package com.jappapps.android.travelbuddy;

import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class TravelBuddy extends Activity {
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           TextView tv = new TextView(this);
           tv.setText("Welcome to TravelBuddy!" +
                   "Submit your tips!");
           setContentView(tv);

       } 

       public class HelloGoogleMaps extends MapActivity {
        @Override
        protected boolean isRouteDisplayed() {
            return false;
        }
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
            MapView mapView = (MapView) findViewById(R.id.addToDictionary);
            mapView.setBuiltInZoomControls(true);
        } 
    }
}
Main.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="0QrW-CcUIzU_fxIS_9O-BkFnuPC-rTj-7t3Q0xw"
/>
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />



</LinearLayout>
Android Manifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.jappapps.android.travelbuddy"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TravelBuddy"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="3" />
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
 
Looks like you combined a couple of classes.

1. Rename Main.xml to main.xml.
2. Use this for TravelBuddy class

Code:
package com.jappapps.android.travelbuddy;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class TravelBuddy extends MapActivity {
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main); // changed to lowercase
           MapView mapView = (MapView) findViewById(R.id.mapview); // match id in main.xml
           mapView.setBuiltInZoomControls(true);
        }

        @Override
        protected boolean isRouteDisplayed() {
            return false;
        }
}
 
Back
Top Bottom