Google Maps Android API v2 and Eclipse - android

I am new in Google Map and so many things aren't clear enough to me for that reason.So i expect some expert's direction on this regard.I read This Guide and did everything what it says.I use google map api v2 and get a map key.Then i make a sample project following that link and select target version android 2.2(while running the project).But a list of error occurs after running then example in eclipse android emulator.My logcat view shows:
01-31 00:51:59.226: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-31 00:51:59.236: E/AndroidRuntime(329): FATAL EXCEPTION: main
01-31 00:51:59.236: E/AndroidRuntime(329): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.googleMapApp/com.googleMapApp.LocationProfileManagerActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.os.Looper.loop(Looper.java:123)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.reflect.Method.invoke(Method.java:521)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 00:51:59.236: E/AndroidRuntime(329): at dalvik.system.NativeStart.main(Native Method)
01-31 00:51:59.236: E/AndroidRuntime(329): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.Activity.setContentView(Activity.java:1647)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.googleMapApp.LocationProfileManagerActivity.onCreate(LocationProfileManagerActivity.java:14)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 00:51:59.236: E/AndroidRuntime(329): ... 11 more
01-31 00:51:59.236: E/AndroidRuntime(329): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.googleMapApp-1.apk]
01-31 00:51:59.236: E/AndroidRuntime(329): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
My Manifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googleMapApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.googleMapApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.googleMapApp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Require OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".LocationProfileManagerActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="myMapKey"/>
</application>
</manifest>
My main.xml is:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
My activity.java is:
package com.googleMapApp;
import android.app.Activity;
import android.os.Bundle;
public class LocationProfileManagerActivity extends Activity {
/** Called when the activity is first created. */
//private GoogleMap map;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
Sorry for this lengthy description,but i want to show you exactly what i did.I think as a newcomer i did a lot of mistake on this way.so i expect someone will guide me that.

You are using features only available in later APIs, namely Fragment. If you want to compile to support 2.2, you need to include the Support Library in your project. You will also have to make the following changes to use support fragments instead of regular fragments --
In main.xml, change
class="com.google.android.gms.maps.MapFragment"/>
to
class="com.google.android.gms.maps.SupportMapFragment"/>
and in your activity.java, change
public class LocationProfileManagerActivity extends Activity {
to
public class LocationProfileManagerActivity extends FragmentActivity {

you need to make two changes
Since as you are sdk version is below 12, need to make following change
1)
main.xml
Replace
class="com.google.android.gms.maps.MapFragment"/>
with
class="com.google.android.gms.maps.SupportMapFragment"/>
2) activity.java
Need to extend FragmentActivity instead of Activity
If you want to test in emulator , then download the google_play_services_apk and install it in emulator.

Maps API v2 cannot be run in an emulator because of its dependency on Google Play Services, which is bundled in the Google Play Store .apk. It can be hacked together though, you can read about it here on the first Google result for "Google maps v2 emulator". Also you can still use V1 for a limited time, you can get started here.

Related

Android Manifest change force closes app

I added a class to my working app. I want the new class to be the first page to load, its called dashboard.class. I added it to the manifest and now the app force closes when you try to load it. I also went and removed the entry in the manifest and the app worked again. Please tell me what I am doing wrong
<activity
android:name="com.magicbuddy.gamble.Dashboard"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.magicbuddy.gamble.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.MagicBuddy.Gamble.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The dashboard is the new class I added. When I remove it and reset MainActivity to LAUNCHER and MAIN, the app will work just fine again.
I tried the posted solutions of removing the intent-filter and it is still crashing. Here is the logcat **Also thank you guys for your replys
01-31 13:56:38.709: D/AndroidRuntime(1995): Shutting down VM
01-31 13:56:38.709: W/dalvikvm(1995): threadid=1: thread exiting with uncaught exception (group=0xb2eda288)
01-31 13:56:38.709: E/AndroidRuntime(1995): FATAL EXCEPTION: main
01-31 13:56:38.709: E/AndroidRuntime(1995): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.magicbuddy.gamble/com.magicbuddy.gamble.Dashboard}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.os.Looper.loop(Looper.java:137)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-31 13:56:38.709: E/AndroidRuntime(1995): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 13:56:38.709: E/AndroidRuntime(1995): at java.lang.reflect.Method.invoke(Method.java:511)
01-31 13:56:38.709: E/AndroidRuntime(1995): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-31 13:56:38.709: E/AndroidRuntime(1995): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-31 13:56:38.709: E/AndroidRuntime(1995): at dalvik.system.NativeStart.main(Native Method)
01-31 13:56:38.709: E/AndroidRuntime(1995): Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
01-31 13:56:38.709: E/AndroidRuntime(1995): at com.magicbuddy.gamble.Dashboard.onCreate(Dashboard.java:25)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.Activity.performCreate(Activity.java:5008)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-31 13:56:38.709: E/AndroidRuntime(1995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
I added a class that has only 4 buttons on it and each button has an image. That is what I want to load first but this is the logcat error when I try to make that happen
According to the logcat the Exception is:
java.lang.ClassCastException: android.widget.ImageButton cannot be
cast to android.widget.Button
This is happening in the onCreate() method of your Dashboard Activity. You are casting an ImageButton to a Button. The problem is not in the manifest but in the class itself.
Try removing the intent-filter from your MainActivity. You really only need to define intent filters when trying to control what types of intents access into your activity, but if that is only going to be called upon by your Dashboard activity as I think it is, then you don't need to include the intent filter as it is part of the same package

Android google map

I am try to add Google MAP Api v2 in my application.but I am getting exception. Exception is
java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.googlemapsv2/info.androidhive.googlemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
Here is my xml class
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
this is my main class
public class MainActivity extends Activity {
private GoogleMap _googleMap=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try
{
//loading map
initilizeMap();
_googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
_googleMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if(_googleMap==null)
{
_googleMap=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
if (_googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
initilizeMap();
}
}
this is my logcat
01-31 14:20:55.603: E/AndroidRuntime(311): FATAL EXCEPTION: main
01-31 14:20:55.603: E/AndroidRuntime(311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demo/com.example.demo.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.os.Looper.loop(Looper.java:123)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 14:20:55.603: E/AndroidRuntime(311): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 14:20:55.603: E/AndroidRuntime(311): at java.lang.reflect.Method.invoke(Method.java:521)
01-31 14:20:55.603: E/AndroidRuntime(311): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 14:20:55.603: E/AndroidRuntime(311): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 14:20:55.603: E/AndroidRuntime(311): at dalvik.system.NativeStart.main(Native Method)
01-31 14:20:55.603: E/AndroidRuntime(311): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-31 14:20:55.603: E/AndroidRuntime(311): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.Activity.setContentView(Activity.java:1647)
01-31 14:20:55.603: E/AndroidRuntime(311): at com.example.demo.MainActivity.onCreate(MainActivity.java:22)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 14:20:55.603: E/AndroidRuntime(311): ... 11 more
01-31 14:20:55.603: E/AndroidRuntime(311): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.demo-2.apk]
01-31 14:20:55.603: E/AndroidRuntime(311): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-31 14:20:55.603: E/AndroidRuntime(311): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-31 14:20:55.603: E/AndroidRuntime(311): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
01-31 14:20:55.603: E/AndroidRuntime(311): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-31 14:20:55.603: E/AndroidRuntime(311): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
You should use SupportMapFragment instead of MapFragment.
Change
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Also change
_googleMap=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
to
_googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
And also If you're using fragments on older devices (pre Honeycomb) you should always extend your Activity from FragmentActivity.
and also check
Add the Google Play services version to your app's manifest
Edit your application's AndroidManifest.xml file, and add the
following declaration within the element. This embeds the version of
Google Play services that the app was compiled with.
You just need to add <meta-data> under <application> tag into your AndroidManifest.xml
....<application>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
This is because latest google play services requires a version name, which is to be mentioned using <meta-data .. /> inside AndroidManifest.xml
Extend your MainActivity from FragmentActivity.
Refer this :
Inflating Google Maps v2 fragment causes ClassNotFoundException
If you are using Fragments your MainActivity must extends FragmentActivity:
public class MainActivity extends FragmentActivity {
//Stuff
}
If you are using the Support-Library so you can use your Fragments in lower Android API Levels use This:
public class MainActivity extends android.support.v4.app.FragmentActivity{
//Stuff
}
And use the SupportFragmentMap in your XML:
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
In your xml try to change from
android:name="com.google.android.gms.maps.MapFragment"
to
android:name="com.google.android.gms.maps.SupportMapFragment"
Check if this work.

setPadding on ImageView crashes activity

I use actionbarcompat to have an actionbar also on pre honeycomp devices.
As there is no space between the home icon and the title of the actionbar, I added this to my activites:
// add padding to the right of home item
ImageView view = (ImageView)findViewById(android.R.id.home);
view.setPadding(0, 0, 10, 0);
Actually the second line (setPadding) is causing the crash.
It is working fine on Jelly Bean devices. But I get a Null Pointer exception running this on e.g. Android 2.3 device.
This is the logcat output of the crash:
12-29 11:44:36.968: E/AndroidRuntime(329): FATAL EXCEPTION: main
12-29 11:44:36.968: E/AndroidRuntime(329): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.GetRichOrDieSmoking/com.GetRichOrDieSmoking.MainScreen}: java.lang.NullPointerException
12-29 11:44:36.968: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.os.Handler.dispatchMessage(Handler.java:99)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.os.Looper.loop(Looper.java:123)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-29 11:44:36.968: E/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 11:44:36.968: E/AndroidRuntime(329): at java.lang.reflect.Method.invoke(Method.java:507)
12-29 11:44:36.968: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-29 11:44:36.968: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-29 11:44:36.968: E/AndroidRuntime(329): at dalvik.system.NativeStart.main(Native Method)
12-29 11:44:36.968: E/AndroidRuntime(329): Caused by: java.lang.NullPointerException
12-29 11:44:36.968: E/AndroidRuntime(329): at com.GetRichOrDieSmoking.MainScreen.onCreate(MainScreen.java:463)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-29 11:44:36.968: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-29 11:44:36.968: E/AndroidRuntime(329): ... 11 more
android.R.id.home was introduced only in API level 11. So the view could not be created in Android 2.3. Hence in the following line when you try to set padding on the null view you get NullPointerException.
you can't access the home view probably because of the API level .
use a third party library for the action bar in order to support low API levels.
i strongly suggest using the actionBarSherlock .

inflating fragments with compatibility package android

I am trying to inflate a layout containing a Fragment using the backwards compatibility package. I took the jar file and placed it in the libs folder of my project. I extended Fragment and then tried to inflate it by setting the contentView of the Activity to
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<fragment
class="com.test.fragments.AdFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/></LinearLayout>
But when I set the content view it fails with a ClassNotFoundException for the fragment tag.
Here is the logcat output.
java.lang.RuntimeException: Unable to start activity ComponentInfo{}: \
android.view.InflateException: Binary XML file line #51: \
Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1777)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1793)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3848)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #51: \
Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:211)
at android.app.Activity.setContentView(Activity.java:1657)
at com.test.base.activities.TabbedStoreActivity.onCreate(TabbedStoreActivity.java:46)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1731)
... 11 more
Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader \
dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar: \
/data/app/com.test.test.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.view.LayoutInflater.createView(LayoutInflater.java:471)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
... 20 more
Make sure your activity is inheriting from FragmentActivity, otherwise <fragment> does not work. Here is a sample project demonstrating this.

Force Down error in MapView

i want to open a map when i click a button but unfortunately my app forces down...this is my logcat:
01-31 18:11:49.465: VERBOSE/InputDevice(2836): ID[0]=0(0) Up(1=>0)
01-31 18:11:49.606: WARN/dalvikvm(6111): Class resolved by unexpected DEX: Lkostas/menu/olympiakos/GoogleMaps;(0x486356d8):0x22f5d8 ref [Lcom/google/android/maps/MapActivity;] Lcom/google/android/maps/MapActivity;(0x486356d8):0x21dca0
01-31 18:11:49.606: WARN/dalvikvm(6111): (Lkostas/menu/olympiakos/GoogleMaps; had used a different Lcom/google/android/maps/MapActivity; during pre-verification)
01-31 18:11:49.606: WARN/dalvikvm(6111): Unable to resolve superclass of Lkostas/menu/olympiakos/GoogleMaps; (67)
01-31 18:11:49.606: WARN/dalvikvm(6111): Link of class 'Lkostas/menu/olympiakos/GoogleMaps;' failed
01-31 18:11:49.610: DEBUG/AndroidRuntime(6111): Shutting down VM
01-31 18:11:49.610: WARN/dalvikvm(6111): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): FATAL EXCEPTION: main
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): java.lang.NoClassDefFoundError: kostas.menu.olympiakos.GoogleMaps
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at kostas.menu.olympiakos.DialogActivity$1.onItemClick(DialogActivity.java:47)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at android.widget.ListView.performItemClick(ListView.java:3672)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at android.os.Handler.handleCallback(Handler.java:587)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at android.os.Handler.dispatchMessage(Handler.java:92)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at android.os.Looper.loop(Looper.java:123)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at java.lang.reflect.Method.invoke(Method.java:521)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at dalvik.system.NativeStart.main(Native Method)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at dalvik.system.DexFile.defineClass(Native Method)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-31 18:11:49.641: ERROR/AndroidRuntime(6111): ... 13 more
01-31 18:11:49.660: WARN/ActivityManager(2836): Force finishing activity kostas.menu.olympiakos/.DialogActivity
thats the way i m calling the map activity:
Intent newActivity111 = new Intent(DialogActivity.this, GoogleMaps.class);
startActivity(newActivity111);
Somehow, your device or emulator has a different implementation of com.google.android.maps.MapActivity than what your compiler used. That should not be possible under normal circumstances. It suggests that you have seriously messed up your build process, such as manually adding the Maps add-on JAR to your build path rather than just setting a Maps-enabled target.
Not too sure whether your problem is related to the libraries available.
Map library is not part of the Standard Android library. Hence you need to declare it in the Manifest file.
Follow the link: http://developer.android.com/resources/tutorials/views/hello-mapview.html
Since the library is not available your Activity "GoogleMaps" which extends MapActivity doesn't get loaded into the system.
All the questions and answers related to getting the Fatal Exception java.lang.NoClassDefFoundError when using a MapActivity did not help me. CommonsWare's response gave me a hint that helped me arrive at my solution.
When I copied my project to a new environment, my setup did not include the Google Maps library. I added the maps.jar file manually into my project and was able to link the application successfully but when I attempted to start the activity that derived from MapActivity I got the fatal exception.
I removed the reference to the maps.jar library. I then noticed I was building against the Android 2.2 SDK. I did not have the Google APIs SDK installed. After downloading and installing the Google APIs SDK, and specifying this SDK as my target, my problem went away.

Categories

Resources