Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6073871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:19:08+00:00 2026-05-23T10:19:08+00:00

There are 3 buttons on the screen! Start, View Map, Stop When I click

  • 0

There are 3 buttons on the screen! Start, View Map, Stop

When I click View Map, it should go to a new screen that shows the map! But something goes wrong and the app is getting force closed! I believe the problem is with the xml files. Please someone correct it.

Main.xml

    <?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView 
android:layout_width="wrap_content" 
android:id="@+id/widget35" 
android:padding="10dp" 
android:textSize="35sp" 
android:text="Maps" 
android:layout_height="wrap_content" />

    <Button 
android:textSize="30sp" 
android:layout_width="wrap_content" 
android:id="@+id/buttonStart" 
android:text="Start" 
android:layout_height="match_parent" />

    <Button 
android:textSize="30sp" 
android:layout_width="wrap_content" 
android:id="@+id/buttonMap" 
android:text="View Map" 
android:layout_height="wrap_content" />

    <Button 
android:textSize="30sp" 
android:layout_width="wrap_content" 
android:id="@+id/buttonStop" 
android:text="Stop" 
android:layout_height="match_parent" />

    <com.google.android.maps.MapView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:enabled="true"
    android:id="@+id/mymap"
    android:apiKey="xxxxxxxxxxx" />

    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/myzoom"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    />
    </RelativeLayout>

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Firstdroid.Gps"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity 
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service 
android:permission="android.permission.INTERNET" 
android:name=".IntentService" 
android:enabled="true"
/>
<service android:name="GPSTestApp" />
<activity android:name=".MapViewer">
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>

MainActivity.java

package Firstdroid.Gps;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import Firstdroid.Gps.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
    MapView myMap;
    private MyLocationOverlay myLocOverlay;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /* MAP BUTTON */

        Button mapButton = (Button) findViewById(R.id.buttonMap);
        mapButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View m){
                    Log.d("Firstdroid.Gps", "Loading Map..");
                    // Loading Google Map View
                    startService(new Intent(MainActivity.this, MapViewer.class));
                }       
        });

    }
}/* End of MainActivity */

In addition to the Map button block, this also has blocks for start and stop, but they work correctly.

MapViewer.java

package Firstdroid.Gps;
//import android.R;
import Firstdroid.Gps.R;
import android.app.Service;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
public class MapViewer extends MainActivity {

    MapView myMap;
    private MyLocationOverlay myLocOverlay;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        initMap();
        initMyLocation();
    }

    private void initMap() {
        myMap = (MapView) findViewById(R.id.mymap);

        View zoomView = myMap.getZoomControls();
        LinearLayout myzoom = (LinearLayout) findViewById(R.id.myzoom);
        myzoom.addView(zoomView);
        myMap.displayZoomControls(true);

    }

    /**
     * Initialises the MyLocationOverlay and adds it to the overlays of the map
     */
    private void initMyLocation() {
        myLocOverlay = new MyLocationOverlay(this, myMap);
        myLocOverlay.enableMyLocation();
        myMap.getOverlays().add(myLocOverlay);

    }

    //@Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

Logcat

06-29 04:34:37.701: WARN/dalvikvm(381): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-29 04:34:37.731: ERROR/AndroidRuntime(381): FATAL EXCEPTION: main
06-29 04:34:37.731: ERROR/AndroidRuntime(381): java.lang.RuntimeException: Unable to start activity ComponentInfo{Firstdroid.Gps/Firstdroid.Gps.MainActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class com.google.android.maps.MapView
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.os.Looper.loop(Looper.java:123)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at java.lang.reflect.Method.invokeNative(Native Method)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at java.lang.reflect.Method.invoke(Method.java:521)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at dalvik.system.NativeStart.main(Native Method)
06-29 04:34:37.731: ERROR/AndroidRuntime(381): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.google.android.maps.MapView
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.Activity.setContentView(Activity.java:1647)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at Firstdroid.Gps.MainActivity.onCreate(MainActivity.java:23)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     ... 11 more
06-29 04:34:37.731: ERROR/AndroidRuntime(381): Caused by: java.lang.ClassNotFoundException: com.google.android.maps.MapView in loader dalvik.system.PathClassLoader[/data/app/Firstdroid.Gps-2.apk]
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.view.LayoutInflater.createView(LayoutInflater.java:466)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
06-29 04:34:37.731: ERROR/AndroidRuntime(381):     ... 20 more
06-29 04:34:37.751: WARN/ActivityManager(58):   Force finishing activity Firstdroid.Gps/.MainActivity
06-29 04:34:38.292: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44fb8580 Firstdroid.Gps/.MainActivity}
06-29 04:34:48.824: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44fb8580 Firstdroid.Gps/.MainActivity}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:19:09+00:00Added an answer on May 23, 2026 at 10:19 am

    You need to create a separate layout .xml file for your map view. Create a new xml called map.xml in res->layout and past this in.

    Note: your MapViewer class should extend a MapActivity, not a MainActivity.

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:orientation="horizontal"
    >
    
    <com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:enabled="true"
    android:apiKey="your API key goes here" />
    
    </LinearLayout> 
    

    Make sure you set the content view to the new file in your map activity.

    setContentView(R.layout.map);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up a close to start button in a game. The
So, I've built an Ok RSS reader for a new sports app I'll be
I hope this isn't a dumb question, as I am rather new to Android,
So im conceptually stuck building my app. I've read lots of forums but I
I'm tryin to create a simple app that basically is a tracker that keeps
I've created a UIScrollView in Interface Builder which takes up the entire screen of
I have create a method for playing a video in a video player and
I have some trouble while try using broadcast receiver. Target: I have three app
I have two frames in my page. The upper frame is a jsp which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.