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 7747951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:39:31+00:00 2026-06-01T10:39:31+00:00

I have a Main class and a HelloWorld class. I have created a button

  • 0

I have a Main class and a HelloWorld class. I have created a button in Main.xml when i click this button it should start HelloWorld activity. When i execute it, It force closes when i click the button. Log cat also given below.

Main.java

import java.io.IOException;
import java.util.List;
import java.util.Locale;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Main extends MapActivity implements LocationListener {
/** Called when the activity is first created. */
MapView map;
long start;
long stop;
int x, y;
GeoPoint touchedPoint;
Drawable d;
List<Overlay> overlayList;
LocationManager lm;
String towers;
int lat ;
   int longi; 





@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    Button button = (Button)findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            //Toast.makeText(Main.this, "you clicked on button!",     Toast.LENGTH_LONG).show();
            Intent intent = new Intent(Main.this, HelloWorld.class);
    startActivity(intent)
        }
    });

    map = (MapView)findViewById(R.id.mv);
    map.setBuiltInZoomControls(true);

    Touchy t = new Touchy();
    overlayList = map.getOverlays();
    overlayList.add(t);

    d = getResources().getDrawable(R.drawable.pinn);

    //Placing pintpoint
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria crit = new Criteria();

    towers = lm.getBestProvider(crit, false);
    Location location = lm.getLastKnownLocation(towers);

    if (location != null){
        lat = (int) (location.getLatitude() *1E6);
        longi= (int) (location.getLongitude() *1E6);



        GeoPoint ourLocation = new GeoPoint(lat,longi);
        OverlayItem overlayItem = new OverlayItem(ourLocation, "Hi!!", "2nd");
        CustomPinPoint custom = new CustomPinPoint(d, Main.this);   
        custom.insertPinpoint(overlayItem);
        overlayList.add(custom);
    }else{
        Toast.makeText(Main.this, "Couldnt get provider", Toast.LENGTH_SHORT).show();
    }





}

@Override
protected void onPause() {
    // TODO Auto-generated method stub

    super.onPause();
    lm.removeUpdates(this);
}


@Override
protected void onResume() {
    // TODO Auto-generated method stub

    super.onResume();
    lm.requestLocationUpdates(towers, 500, 1, this );
}


    @Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}



class Touchy extends Overlay{
    public boolean onTouchEvent(MotionEvent e, MapView m){
    if (e.getAction() == MotionEvent.ACTION_DOWN){
        start = e.getEventTime();

    }
    if (e.getAction() == MotionEvent.ACTION_UP){
        stop = e.getEventTime();
        x = (int) e.getX();
        y = (int) e.getY();
        touchedPoint = map.getProjection().fromPixels(x, y);

    }
    if (stop - start > 1500){
        AlertDialog alert = new AlertDialog.Builder(Main.this).create();
        alert.setTitle("Pick Option");


        alert.setButton("Hello", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                OverlayItem overlayItem = new OverlayItem(touchedPoint, "Hi!!", "2nd");
                CustomPinPoint custom = new CustomPinPoint(d, Main.this);   
                custom.insertPinpoint(overlayItem);
                overlayList.add(custom);



        }
        });
        alert.setButton3("Get Address", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
            Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
            try{
                List<Address> address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() / 1E6, touchedPoint.getLongitudeE6() / 1E6 , 1);
                if (address.size() > 0){
                    String display = "";
                    for (int i = 0; i<address.get(0).getMaxAddressLineIndex(); i++){

                        display += address.get(0).getAddressLine(i) + "\n";
                    }
                    Toast t = Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG);
                    t.show();
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{
            }
        }});
        alert.setButton2("Toggle View", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                if (map.isSatellite()){
                    map.setSatellite(false);
                    map.setStreetView(true);
                }else{
                    map.setStreetView(false);
                    map.setSatellite(true);
                }
            }
});
        alert.setButton("Place a Pin", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                OverlayItem overlayItem = new OverlayItem(touchedPoint, "Hi!!", "2nd");
                CustomPinPoint custom = new CustomPinPoint(d, Main.this);   
                custom.insertPinpoint(overlayItem);
                overlayList.add(custom);

            }


        });
        alert.show();
        return true;
    }

        return false;
    }

}



public void onLocationChanged(Location l) {
    // TODO Auto-generated method stub
    lat = (int) (l.getLatitude() *1E6);
    longi = (int) (l.getLongitude() *1E6);
    GeoPoint ourLocation = new GeoPoint(lat,longi);
    OverlayItem overlayItem = new OverlayItem(ourLocation, "Hi!!", "2nd");
    CustomPinPoint custom = new CustomPinPoint(d, Main.this);   
    custom.insertPinpoint(overlayItem);
    overlayList.add(custom);

}




public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}




public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}




public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}

}

HelloWorld.java

import com.google.android.maps.OverlayItem;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class HelloWorld extends Activity
{

    protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    Button button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v)
        {
            Toast.makeText(HelloWorld.this, "you clicked on button![enter image description here][3]", Toast.LENGTH_LONG).show();
        }
});

Log cat

04-04 22:56:21.623: W/dalvikvm(309): threadid=1: thread exiting with uncaught exception    (group=0x4001d800)
04-04 22:56:21.703: E/AndroidRuntime(309): FATAL EXCEPTION: main
04-04 22:56:21.703: E/AndroidRuntime(309): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mehul.googlemaps/com.mehul.googlemaps.HelloWorld}: android.view.InflateException: Binary XML file line #20: Error inflating class <unknown>
04-04 22:56:21.703: E/AndroidRuntime(309):  at        android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-04 22:56:21.703: E/AndroidRuntime(309):  at  android.os.Handler.dispatchMessage(Handler.java:99)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.os.Looper.loop(Looper.java:123)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-04 22:56:21.703: E/AndroidRuntime(309):  at java.lang.reflect.Method.invokeNative(Native Method)
04-04 22:56:21.703: E/AndroidRuntime(309):  at java.lang.reflect.Method.invoke(Method.java:521)
04-04 22:56:21.703: E/AndroidRuntime(309):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-04 22:56:21.703: E/AndroidRuntime(309):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-04 22:56:21.703: E/AndroidRuntime(309):  at dalvik.system.NativeStart.main(Native   Method)
04-04 22:56:21.703: E/AndroidRuntime(309): Caused by: android.view.InflateException:    Binary XML file line #20: Error inflating class <unknown>
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-04 22:56:21.703: E/AndroidRuntime(309):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.app.Activity.setContentView(Activity.java:1647)
04-04 22:56:21.703: E/AndroidRuntime(309):  at com.mehul.googlemaps.HelloWorld.onCreate(HelloWorld.java:20)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-04 22:56:21.703: E/AndroidRuntime(309):  ... 11 more
04-04 22:56:21.703: E/AndroidRuntime(309): Caused by: java.lang.reflect.InvocationTargetException
04-04 22:56:21.703: E/AndroidRuntime(309):  at com.google.android.maps.MapView.<init>(MapView.java:238)
04-04 22:56:21.703: E/AndroidRuntime(309):  at java.lang.reflect.Constructor.constructNative(Native Method)
04-04 22:56:21.703: E/AndroidRuntime(309):  at   java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-04 22:56:21.703: E/AndroidRuntime(309):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-04 22:56:21.703: E/AndroidRuntime(309):  ... 21 more
04-04 22:56:21.703: E/AndroidRuntime(309): Caused by:   java.lang.IllegalArgumentException: MapViews can only be created inside instances of   MapActivity.
04-04 22:56:21.703: E/AndroidRuntime(309):  at com.google.android.maps.MapView.<init>(MapView.java:282)
04-04 22:56:21.703: E/AndroidRuntime(309):  at com.google.android.maps.MapView.<init>(MapView.java:255)
04-04 22:56:21.703: E/AndroidRuntime(309):  ... 25 more

If anything else is required let me know.. will put it up.

  • 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-06-01T10:39:33+00:00Added an answer on June 1, 2026 at 10:39 am

    Here is the logcat you have to watch out for

    04-04 22:56:21.703: E/AndroidRuntime(309): Caused by:   java.lang.IllegalArgumentException: MapViews can only be created inside instances of   MapActivity.
    

    What you can do is, create a test.xml file with the following

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView
        android:id="@+id/hellotv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
    
    
    </LinearLayout>
    

    and in your HelloWorld do setContentView(R.layout.test);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created simple project with class Main and public static void main and
I have a blank HelloWorld Application: package tutorials.TestReceivers; import android.app.Activity; import android.os.Bundle; public class
I have a main class in a program that launches another class that handles
I have a main class(which is basically a netbeans form;drag and drop) from where
I have a question about the 'Event Dispatch Thread'. I have a Main class
I have a Class(call it main class) and the method in main class calls
I have a small Java test app in Netbeans where the main() class reads
I have the next scenario: I define an int[][] variable in my main class.
I have a Service class and an main Acitivity class which is supposed to
i have any div for show details of project ( class main ). now

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.