I have been working on this Tab View and I finally got it working and all my icons in just right. I went to place a Map View in one of the Tabs just like I would with any other class. For some reason it is not work when I launch the app, it force closes right away. This is the error from LogCat:
11-24 02:06:36.345: E/dalvikvm(1978): Could not find class 'com.nyneaxis.api.gascloud.StationsMap', referenced from method com.nyneaxis.api.gascloud.GasCloudMain.onCreate
11-24 02:06:36.493: E/AndroidRuntime(1978): Uncaught handler: thread main exiting due to uncaught exception
11-24 02:06:36.514: E/AndroidRuntime(1978): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyneaxis.api.gascloud/com.nyneaxis.api.gascloud.GasCloudMain}: android.view.InflateException: Binary XML file line #24: Error inflating class com.google.android.maps.MapView
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.os.Looper.loop(Looper.java:123)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.ActivityThread.main(ActivityThread.java:4363)
11-24 02:06:36.514: E/AndroidRuntime(1978): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 02:06:36.514: E/AndroidRuntime(1978): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 02:06:36.514: E/AndroidRuntime(1978): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-24 02:06:36.514: E/AndroidRuntime(1978): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-24 02:06:36.514: E/AndroidRuntime(1978): at dalvik.system.NativeStart.main(Native Method)
11-24 02:06:36.514: E/AndroidRuntime(1978): Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class com.google.android.maps.MapView
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-24 02:06:36.514: E/AndroidRuntime(1978): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.Activity.setContentView(Activity.java:1622)
11-24 02:06:36.514: E/AndroidRuntime(1978): at com.nyneaxis.api.gascloud.GasCloudMain.onCreate(GasCloudMain.java:13)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
11-24 02:06:36.514: E/AndroidRuntime(1978): ... 11 more
11-24 02:06:36.514: E/AndroidRuntime(1978): Caused by: java.lang.ClassNotFoundException: com.google.android.maps.MapView in loader dalvik.system.PathClassLoader@44e83990
11-24 02:06:36.514: E/AndroidRuntime(1978): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-24 02:06:36.514: E/AndroidRuntime(1978): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-24 02:06:36.514: E/AndroidRuntime(1978): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
11-24 02:06:36.514: E/AndroidRuntime(1978): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
This is my Main class:
package com.nyneaxis.api.gascloud;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class GasCloudMain extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Profile.class);
spec = tabHost
.newTabSpec("profile")
.setIndicator("Profile",
res.getDrawable(R.drawable.ic_tab_profile))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, StationsList.class);
spec = tabHost
.newTabSpec("stations")
.setIndicator("Stations",
res.getDrawable(R.drawable.ic_tab_station))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SearchStations.class);
spec = tabHost
.newTabSpec("search")
.setIndicator("Search",
res.getDrawable(R.drawable.ic_tab_search))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, StationsMap.class);
spec = tabHost
.newTabSpec("map")
.setIndicator("Map",
res.getDrawable(R.drawable.ic_tab_maps))
.setContent(new Intent(this, StationsMap.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp" />
</LinearLayout>
</TabHost>
maps class
package com.nyneaxis.api.gascloud;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.widget.LinearLayout;
public class StationsMap extends MapActivity {
LinearLayout linearLayout;
MapView mapView;
public void onCreate(Bundle savedInstanceState){
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
maps.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="ABQIAAAAYc7mzgA4G-2FaBLUHTM_1xTjBItGPNb7O-Zq4IGUb6RxSdEi4RQ7Y-p4UARzkmuBTxknyrJRWOA31w"
/>
</RelativeLayout>
Please help, I am lost to what I need to do. I can run the maps class withtout the tabs and it works. Thank you in advance. PS I have triends a few things by Googling but nothing close to what I want to accomplish.
Make sure you have the following in your AndroidManifest.xml file.
In the
<application>tag you should have:Hope this helps!