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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:02:41+00:00 2026-05-25T17:02:41+00:00

My android app keeps crashing but there aren’t any errors. Heres the codes. LocationActivity.java

  • 0

My android app keeps crashing but there aren’t any errors.
Heres the codes.

LocationActivity.java
UPDATED

package com.marakana.tutomaps;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class LocationActivity extends TabActivity {

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

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec1, spec2, spec3;  // Resusable TabSpec for each tab
    Intent intent1, intent2, intent3;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent1 = new Intent().setClass(this, HaffActivity.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec1 = tabHost.newTabSpec("Haff").setIndicator("Haff",
                      res.getDrawable(R.drawable.ic_tab_haff))
                  .setContent(intent1);
    tabHost.addTab(spec1);

    // Do the same for the other tabs
    intent2 = new Intent().setClass(this, MapsActivity.class);
    spec2 = tabHost.newTabSpec("Maps").setIndicator("Maps",
                      res.getDrawable(R.drawable.ic_tab_maps))
                  .setContent(intent2);
    tabHost.addTab(spec2);

    intent3 = new Intent().setClass(this, ProfileActivity.class);
    spec3 = tabHost.newTabSpec("Profile").setIndicator("Profile",
                      res.getDrawable(R.drawable.ic_tab_profile))
                  .setContent(intent3);
    tabHost.addTab(spec3);

    tabHost.setCurrentTab(2);
}
}

Here is the main layout file. UPDATED
*main.xml*

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

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent"      android:layout_height="fill_parent">
        <View android:layout_width="fill_parent" android:layout_height="0.5dip"
            android:background="#000" />
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_marginLeft="0dip" android:layout_marginRight="0dip" />
        <View android:layout_width="fill_parent" android:layout_height="2dip"
            android:background="#696969" />
        <View android:layout_width="fill_parent" android:layout_height="2dip"
            android:background="#000" />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent" />
    </LinearLayout>
</TabHost>

Heres the manifest file UPDATED

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.marakana.tutomaps"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".LocationActivity"
              android:label="@string/app_name">
        <intent-filter>
                    <uses-library android:name="com.google.android.maps" />
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity android:name=".HaffActivity">
</activity>

<activity android:name=".MapsActivity">
</activity>

<activity android:name=".ProfileActivity">
</activity>

</application>

MapsActivity.java

   package com.marakana.tutomaps;

   import java.io.IOException;
   import java.util.List;

   import android.location.Address;
   import android.location.Geocoder;
   import android.location.Location;
   import android.location.LocationListener;
   import android.location.LocationManager;
   import android.os.Bundle;
   import android.util.Log;
   import android.widget.TextView;

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

   public class MapsActivity extends MapActivity implements LocationListener {

private static final String TAG = "MapsActivity";

LocationManager locationManager;
Geocoder geocoder;
TextView locationText;
MapView map;    
MapController mapController;

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

    locationText = (TextView)this.findViewById(R.id.lblLocationInfo);
    map = (MapView)this.findViewById(R.id.mapview);
    map.setBuiltInZoomControls(true);

    mapController = map.getController();
    mapController.setZoom(16);

    locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);

    geocoder = new Geocoder(this);

    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location != null) {
        Log.d(TAG, location.toString());
        this.onLocationChanged(location);   
    }
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    locationManager.removeUpdates(this);
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, this);
}

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

@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    Log.d(TAG, "onLocationChanged with location " + location.toString());
    // Displays lat, long, altitude and bearing
    String text = String.format("Lat:\t %f\nLong:\t %f\nAlt:\t %f\nBearing:\t %f", location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getBearing());
    this.locationText.setText(text);

    try {
        // This gets a list of addresses 
        List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10);
        for (Address address : addresses) {
            this.locationText.append("\n" + address.getAddressLine(0));
        }

        // Convert latitude and longitude into int that the GeoPoint constructor can understand
        int latitude = (int)(location.getLatitude() * 1000000);
        int longitude = (int)(location.getLongitude() * 1000000);

        GeoPoint point = new GeoPoint(latitude,longitude);
        mapController.animateTo(point);

    } catch (IOException e) {
        Log.e("LocateMe", "Could not get Geocoder data", e);
    }
}

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

}

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

}

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

}
   }

Please help me.

  • 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-25T17:02:41+00:00Added an answer on May 25, 2026 at 5:02 pm

    I think you did one mistake…
    You are passing Layout value instead of intent..

    just check your code with mine.. you are passing R.layout.hafflayout instead of intent in setContent(intent); line

    Updated

    TabHost.TabSpec spec1,spec2,spec3;  // Resusable TabSpec for each tab
    Intent intent1,intent2,intent3;
    intent1 = new Intent().setClass(this, HaffActivity.class);
    
    // Initialize a TabSpec for each tab and add it to the TabHost
    spec1 = tabHost.newTabSpec("Haff").setIndicator("Haff",
                      res.getDrawable(R.drawable.ic_tab_haff))
                  .setContent(intent1);
    tabHost.addTab(spec);
    
    // Do the same for the other tabs
    intent2 = new Intent().setClass(this, MapsActivity.class);
    spec2 = tabHost.newTabSpec("Maps").setIndicator("Maps",
                      res.getDrawable(R.drawable.ic_tab_maps))
                  .setContent(intent2);
    tabHost.addTab(spec);
    
    intent3 = new Intent().setClass(this, ProfileActivity.class);
    spec3 = tabHost.newTabSpec("Profile").setIndicator("Profile",
                      res.getDrawable(R.drawable.ic_tab_profile))
                  .setContent(intent3);
    tabHost.addTab(spec);
    

    Update:

    you didnt add dot(.) before activity’s name in menifest.xml

    <activity android:name=".HaffActivity">
    </activity>
    
    <activity android:name=".MapsActivity">
    </activity>
    
    <activity android:name=".ProfileActivity">
    </activity>
    

    Update…Latest

    in your MapsActivity.class you setContentView(R.layout.main); so please change it and add your xml for MapActivity

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

Sidebar

Related Questions

my app keeps force closing before it starts... eclipse returns no errors in my
in my android app i have an ui-update-thread that keeps all my views up-to-date.
I can run this code in Android app (using PhoneGap adn jQuery Mobile) but
I am trying to use my LG Revolution to develop an Android app but
I'm trying to use a custom class (be.myname.rssreader.util.Global) extending android.app.Application, but when I try
My android app has a two word app name, and the 2nd word doesn't
I'm building an Android app and I want to copy the text value of
We have an Android app and a Web Service. We want to download part
I have an Android app with a ListActivity in the main view. The list
I've got an Android app which has a periodic background Service. I want this

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.