I am new to android and using google map v2 for the 1st time by looking at android developer tutorials. getting exceptions and don't know what is wrong. Can someone help me out ?
LOG CAT
03-12 22:00:01.678: D/AndroidRuntime(278): Shutting down VM
03-12 22:00:01.678: W/dalvikvm(278): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
03-12 22:00:01.758: E/AndroidRuntime(278): FATAL EXCEPTION: main
03-12 22:00:01.758: E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sameer.example.maps_example/com.sameer.example.maps_example.MainActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class fragment
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.os.Handler.dispatchMessage(Handler.java:99)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.os.Looper.loop(Looper.java:123)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-12 22:00:01.758: E/AndroidRuntime(278): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 22:00:01.758: E/AndroidRuntime(278): at java.lang.reflect.Method.invoke(Method.java:521)
03-12 22:00:01.758: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-12 22:00:01.758: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-12 22:00:01.758: E/AndroidRuntime(278): at dalvik.system.NativeStart.main(Native Method)
03-12 22:00:01.758: E/AndroidRuntime(278): Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class fragment
03-12 22:00:01.758: E/AndroidRuntime(278): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-12 22:00:01.758: E/AndroidRuntime(278): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.Activity.setContentView(Activity.java:1647)
03-12 22:00:01.758: E/AndroidRuntime(278): at com.sameer.example.maps_example.MainActivity.onCreate(MainActivity.java:11)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-12 22:00:01.758: E/AndroidRuntime(278): ... 11 more
03-12 22:00:01.758: E/AndroidRuntime(278): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.sameer.example.maps_example-2.apk]
03-12 22:00:01.758: E/AndroidRuntime(278): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
03-12 22:00:01.758: E/AndroidRuntime(278): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
03-12 22:00:01.758: E/AndroidRuntime(278): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
03-12 22:00:01.758: E/AndroidRuntime(278): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-12 22:00:01.758: E/AndroidRuntime(278): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
03-12 22:00:01.758: E/AndroidRuntime(278): ... 19 more
XML LAYOUT FILE
<?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"
android:name="com.google.android.gms.maps.MapFragment"/>
Java File
package com.sameer.example.maps_example;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sameer.example.maps_example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<permission
android:name="com.sameer.example.maps_example.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.sameer.example.maps_example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You are writing application for API V8 but you are using MapFragment and Activity classes.
instead you should use the android-support-v4 library and use the SupportMapFragment and FragmentActvity classes.
To add the support library to the project you need to download it using the SDK Manager.
and then you can right click your project and chose Android Tools -> SupportLibrary.
Then extand your map Activity from FragmentActivity and make shure you are importing:
android.support.v4.app.FragmentActivity
in you XML file use the SupportMapFragment class instead of MapFragment, like so:
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Related
I have made an app that uses Google Android Maps API V2 and I have followed every step in the guide provided by Google but it doesn't work unfortunely and it crashes every time I try to start it up. So I'm wondering what is the problem?
MainActivity.java
package com.android.maptest;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
<?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"
android:name="com.google.android.gms.maps.MapFragment"/>
Maptest Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.maptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<permission
android:name="com.android.maptest.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.android.maptest.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:debuggable="true" >
<activity
android:name="com.android.maptest.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api_key" />
</application>
</manifest>
Logcat
03-12 09:46:13.150: D/AndroidRuntime(1547): Shutting down VM
03-12 09:46:13.150: W/dalvikvm(1547): threadid=1: thread exiting with uncaught exception (group=0x410e22a0)
03-12 09:46:13.155: E/AndroidRuntime(1547): FATAL EXCEPTION: main
03-12 09:46:13.155: E/AndroidRuntime(1547): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.maptest/com.android.maptest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-12 09:46:13.155: E/AndroidRuntime(1547): at
android.app.ActivityThread.access$600(ActivityThread.java:140)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.os.Handler.dispatchMessage(Handler.java:99)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.os.Looper.loop(Looper.java:137)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.reflect.Method.invoke(Method.java:511)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-12 09:46:13.155: E/AndroidRuntime(1547): at dalvik.system.NativeStart.main(Native Method)
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.setContentView(Activity.java:1924)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.maptest.MainActivity.onCreate(MainActivity.java:11)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.performCreate(Activity.java:5206)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 11 more
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:584)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:552)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.onCreateView(Activity.java:4849)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 20 more
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:574)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 23 more
03-12 09:51:21.560: I/Process(1547): Sending signal. PID: 1547 SIG: 9
Here a blog post I wrote on how to integrate Google Maps into you application:
Creating Google Map Application
From your error it look like you did not perform correctly steps 2-3 of the blog guide,
for adding Google Play services library into your application.
If you follow carefully the steps written in the guide you will end up with the end result you can see at the end of the post.
I assumed that you have already get Google Maps Android API v2 key and have Google Play services. If you not have already installed it then please follow below steps to solve this problem_
Step 1. you can found it in Android SDK Manager under Extras tick check box of -Google Play services install it and after complete installation, restart your Eclipse.
Step 2. Add library named_ google-play-services_lib found under the extras folder of your Android SDK setup folder to your Android project_
Path of google service lib_
{Your_Android_SDK_direct}\extras\google\google_play_services\libproject\google-play-services_lib
Ex. Location of this lib on My system_
C:\Program Files\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib
I hope this will solve your ploblem.
For me adding:
import com.google.android.gms.maps.SupportMapFragment;
And changing the xml to
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header" />
resolved the problem. I hope you resolve it too!
Looks like you didn't add the Google Play Services library to your project.
It's located at {Android SDK}\extras\google\google_play_services
Add it as Android Library Project to Eclipse and then add it to your project.
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.
Im designing my first android application and keep coming up with the following error which is draining the life out of me and I do not understand it very well (Please find my Logcat (verbose), Java Code(this i played around with and this began to occur once started to work on my editButton and buttonUpdate bit. Does it have anything to do with the editStatus? I really think it may) and I have also put in my manifest file:
LOGCAT verbose
04-21 15:30:23.388: D/AndroidRuntime(276): Shutting down VM
04-21 15:30:23.388: W/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-21 15:30:23.427: E/AndroidRuntime(276): FATAL EXCEPTION: main
04-21 15:30:23.427: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.locator.demo/com.locator.demo.LocatorDemoActivity}: java.lang.ClassCastException: android.widget.TextView
04-21 15:30:23.427: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-21 15:30:23.427: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
04-21 15:30:23.427: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
04-21 15:30:23.427: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-21 15:30:23.427: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-21 15:30:23.427: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)
04-21 15:30:23.427: E/AndroidRuntime(276): Caused by: java.lang.ClassCastException: android.widget.TextView
04-21 15:30:23.427: E/AndroidRuntime(276): at com.locator.demo.LocatorDemoActivity.onCreate(LocatorDemoActivity.java:21)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-21 15:30:23.427: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-21 15:30:23.427: E/AndroidRuntime(276): ... 11 more
04-21 15:35:23.607: I/Process(276): Sending signal. PID: 276 SIG: 9
04-21 15:50:32.127: D/AndroidRuntime(301): Shutting down VM
04-21 15:50:32.127: W/dalvikvm(301): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-21 15:50:32.147: E/AndroidRuntime(301): FATAL EXCEPTION: main
04-21 15:50:32.147: E/AndroidRuntime(301): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.locator.demo/com.locator.demo.LocatorDemoActivity}: java.lang.ClassCastException: android.widget.TextView
04-21 15:50:32.147: E/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.os.Looper.loop(Looper.java:123)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-21 15:50:32.147: E/AndroidRuntime(301): at java.lang.reflect.Method.invokeNative(Native Method)
04-21 15:50:32.147: E/AndroidRuntime(301): at java.lang.reflect.Method.invoke(Method.java:521)
04-21 15:50:32.147: E/AndroidRuntime(301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-21 15:50:32.147: E/AndroidRuntime(301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-21 15:50:32.147: E/AndroidRuntime(301): at dalvik.system.NativeStart.main(Native Method)
04-21 15:50:32.147: E/AndroidRuntime(301): Caused by: java.lang.ClassCastException: android.widget.TextView
04-21 15:50:32.147: E/AndroidRuntime(301): at com.locator.demo.LocatorDemoActivity.onCreate(LocatorDemoActivity.java:21)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-21 15:50:32.147: E/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-21 15:50:32.147: E/AndroidRuntime(301): ... 11 more
CODE:
package com.locator.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class LocatorDemoActivity extends Activity implements OnClickListener {
EditText editStatus;
Button buttonUpdate;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationstatus);
editStatus = (EditText)findViewById(R.id.edit_status);
buttonUpdate = (Button)findViewById(R.id.button_update);
buttonUpdate.setOnClickListener(this);
//have button 'listen' for click
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
ANDROID Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.locator.demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_main" >
<activity
android:name=".LocatorDemoActivity"
android:label="#string/app_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have;
attempted to do adb kill-server and adb start-server and run it with an without an emulator as suggested in another post. Please be slightly understanding as my knowledge of eclipse and Java is pretty low and im learning.
Please help
As seen from this error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.locator.demo/com.locator.demo.LocatorDemoActivity}:
java.lang.ClassCastException: android.widget.TextView
And this one:
Caused by: java.lang.ClassCastException: android.widget.TextView
You are trying to cast a TextView to EditText ( in this line: editStatus = (EditText)findViewById(R.id.edit_status);).
Go to locationstatus.xml, and change the TextView with the id edit_status to EditText.
12-20 13:52:15.071: D/AndroidRuntime(278): Shutting down VM
12-20 13:52:15.081: W/dalvikvm(278): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-20 13:52:15.100: E/AndroidRuntime(278): FATAL EXCEPTION: main
12-20 13:52:15.100: E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebonybutler.cexample3/com.ebonybutler.cexample3.Main}: java.lang.NullPointerException
12-20 13:52:15.100: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.os.Looper.loop(Looper.java:123)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-20 13:52:15.100: E/AndroidRuntime(278): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 13:52:15.100: E/AndroidRuntime(278): at java.lang.reflect.Method.invoke(Method.java:521)
12-20 13:52:15.100: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-20 13:52:15.100: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-20 13:52:15.100: E/AndroidRuntime(278): at dalvik.system.NativeStart.main(Native Method)
12-20 13:52:15.100: E/AndroidRuntime(278): Caused by: java.lang.NullPointerException
12-20 13:52:15.100: E/AndroidRuntime(278): at com.ebonybutler.cexample3.Main.onCreate(Main.java:21)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-20 13:52:15.100: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-20 13:52:15.100: E/AndroidRuntime(278): ... 11 moreenter code here
These lines here:
12-20 13:52:15.100: E/AndroidRuntime(278): Caused by: java.lang.NullPointerException
12-20 13:52:15.100: E/AndroidRuntime(278): at com.ebonybutler.cexample3.Main.onCreate(Main.java:21)
suggest that something being used on line 21 of cexample3.Main.onCreate is null, so the code can't continue to execute.
I suggest placing a breakpoint above that line, then debugging to see what object is supposed to be available there. Then you can drill down to finding why that object isn't available (for example, maybe it wasn't initialized properly, or perhaps it has gone out of scope by that point).
Added:
Based on your comment above
Hi guys, this is what is on line 21:b.setOnClickListener(new OnClickListener() – user1026229
it looks like the object represented with the variable 'b' (b.setOnClickListener...) probably is null. If so, next step is to find out why...
Check that all the ids(for buttons ) you given correctly or not
These are the possible conditions for your problem.
1. you didnt done proper type casting for widgets.
2. some value is null in oncreate method.
so try to check one again main.java oncreate method and check you given all userpermissions properly
I am getting this error in my application, and this happens only on UPC300-2.2 Viewsonic G-Tablet. All answers I've found so far (including this one) adviced on putting
<uses-permission android:name="android.permission.INTERNET"/>
to the manifest file, but it doesn't help.
Here is the complete stacktrace:
java.lang.NoClassDefFoundError: android.net.NetworkConnectivityListener
at
com.google.android.maps.MapActivity.onCreate(MapActivity.java:199)
at
myapp.Activity.ActivityMapSearch.onCreate(ActivityMapSearch.java:99)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at
android.os.Handler.dispatchMessage(Handler.java:99)
at
android.os.Looper.loop(Looper.java:123)
at
android.app.ActivityThread.main(ActivityThread.java:4627)
at
java.lang.reflect.Method.invokeNative(Native
Method) at
java.lang.reflect.Method.invoke(Method.java:521)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at
dalvik.system.NativeStart.main(Native
Method)
If that is TRUE, you can grab the source code of the class from the Android Source and add it yourself