MapView not working


Last Updated:

  1. joyu12

    joyu12 New Member This Topic's Starter

    Joined:
    Feb 13, 2010
    Messages:
    4
    Likes Received:
    0
    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 (Text):
    1. package com.jappapps.android.travelbuddy;
    2.  
    3. import android.R;
    4. import android.app.Activity;
    5. import android.os.Bundle;
    6. import android.widget.TextView;
    7.  
    8. import com.google.android.maps.MapActivity;
    9. import com.google.android.maps.MapView;
    10.  
    11. public class TravelBuddy extends Activity {
    12.        /** Called when the activity is first created. */
    13.        @Override
    14.        public void onCreate(Bundle savedInstanceState) {
    15.            super.onCreate(savedInstanceState);
    16.            TextView tv = new TextView(this);
    17.            tv.setText("Welcome to TravelBuddy!" +
    18.                    "Submit your tips!");
    19.            setContentView(tv);
    20.  
    21.        }
    22.  
    23.        public class HelloGoogleMaps extends MapActivity {
    24.         @Override
    25.         protected boolean isRouteDisplayed() {
    26.             return false;
    27.         }
    28.         @Override
    29.         public void onCreate(Bundle savedInstanceState) {
    30.             super.onCreate(savedInstanceState);
    31.            
    32.             MapView mapView = (MapView) findViewById(R.id.addToDictionary);
    33.             mapView.setBuiltInZoomControls(true);
    34.         }
    35.     }
    36. }
    Main.xml:
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent"
    6.     >
    7. <com.google.android.maps.MapView
    8.     xmlns:android="http://schemas.android.com/apk/res/android"
    9.     android:id="@+id/mapview"
    10.     android:layout_width="fill_parent"
    11.     android:layout_height="fill_parent"
    12.     android:clickable="true"
    13.     android:apiKey="0QrW-CcUIzU_fxIS_9O-BkFnuPC-rTj-7t3Q0xw"
    14. />
    15. <TextView  
    16.     android:layout_width="fill_parent"
    17.     android:layout_height="wrap_content"
    18.     android:text="@string/hello"
    19.     />
    20.  
    21.  
    22.  
    23. </LinearLayout>
    Android Manifest:
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.       package="com.jappapps.android.travelbuddy"
    4.       android:versionCode="1"
    5.       android:versionName="1.0">
    6.     <application android:icon="@drawable/icon" android:label="@string/app_name">
    7.         <activity android:name=".TravelBuddy"
    8.                   android:label="@string/app_name">
    9.             <intent-filter>
    10.                 <action android:name="android.intent.action.MAIN" />
    11.                 <category android:name="android.intent.category.LAUNCHER" />
    12.             </intent-filter>
    13.         </activity>
    14.  
    15.     </application>
    16.     <uses-sdk android:minSdkVersion="3" />
    17. <uses-library android:name="com.google.android.maps" />
    18. <uses-permission android:name="android.permission.INTERNET" />
    19. </manifest>
    20.  
     

    Advertisement
  2. joyu12

    joyu12 New Member This Topic's Starter

    Joined:
    Feb 13, 2010
    Messages:
    4
    Likes Received:
    0
    I really need some help on this one!
     
  3. billybobbain

    billybobbain Member

    Joined:
    Jan 21, 2010
    Messages:
    6
    Likes Received:
    0
    Looks like you combined a couple of classes.

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

    Code (Text):
    1. package com.jappapps.android.travelbuddy;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.widget.TextView;
    6.  
    7. import com.google.android.maps.MapActivity;
    8. import com.google.android.maps.MapView;
    9.  
    10. public class TravelBuddy extends MapActivity {
    11.        /** Called when the activity is first created. */
    12.        @Override
    13.        public void onCreate(Bundle savedInstanceState) {
    14.            super.onCreate(savedInstanceState);
    15.            setContentView(R.layout.main); // changed to lowercase
    16.            MapView mapView = (MapView) findViewById(R.id.mapview); // match id in main.xml
    17.            mapView.setBuiltInZoomControls(true);
    18.         }
    19.  
    20.         @Override
    21.         protected boolean isRouteDisplayed() {
    22.             return false;
    23.         }
    24. }
    25.  
     
  4. joyu12

    joyu12 New Member This Topic's Starter

    Joined:
    Feb 13, 2010
    Messages:
    4
    Likes Received:
    0
    Still not working :/
     
  5. araujoivan

    araujoivan New Member

    Joined:
    Oct 17, 2010
    Messages:
    2
    Likes Received:
    0
    Hi, your <uses-library > node must be between <application> </aplication> nodes.
     

Share This Page

Loading...