App crashes if I extend FragmentActivity - android

I have been trying to extend FragmentActivity. The same app works if I extend the MainActivity class to Activity and import necessary packages for a normal Activity.
The basic need is that i cannot access the map in a normal activity. It needs to extend FragmentActivity to run the following line.
googleMap= ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
Here is the Java code
package com.dacoders.locationtodo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Here is the layout XML
<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"/>
Here is the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dacoders.locationtodo"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.dacoders.locationtodo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.dacoders.locationtodo.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<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:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.dacoders.locationtodo.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_HERE"/>
</application>
</manifest>
Here is the LOG
0622 21:01:25.911: D/dalvikvm(13621): Lateenabling CheckJNI
0622 21:01:25.991: D/AndroidRuntime(13621): Shutting down VM
0622 21:01:25.991: W/dalvikvm(13621): threadid=1: thread exiting with uncaught exception (group=0x41629930)
0622 21:01:26.001: E/AndroidRuntime(13621): FATAL EXCEPTION: main
0622 21:01:26.001: E/AndroidRuntime(13621): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dacoders.locationtodo/com.dacoders.locationtodo.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.ActivityThread.access$600(ActivityThread.java:141)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.os.Handler.dispatchMessage(Handler.java:99)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.os.Looper.loop(Looper.java:137)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.ActivityThread.main(ActivityThread.java:5041)
0622 21:01:26.001: E/AndroidRuntime(13621): at java.lang.reflect.Method.invokeNative(Native Method)
0622 21:01:26.001: E/AndroidRuntime(13621): at java.lang.reflect.Method.invoke(Method.java:511)
0622 21:01:26.001: E/AndroidRuntime(13621): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
0622 21:01:26.001: E/AndroidRuntime(13621): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
0622 21:01:26.001: E/AndroidRuntime(13621): at dalvik.system.NativeStart.main(Native Method)
0622 21:01:26.001: E/AndroidRuntime(13621): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
0622 21:01:26.001: E/AndroidRuntime(13621): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
0622 21:01:26.001: E/AndroidRuntime(13621): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.Activity.setContentView(Activity.java:1881)
0622 21:01:26.001: E/AndroidRuntime(13621): at com.dacoders.locationtodo.MainActivity.onCreate(MainActivity.java:12)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.Activity.performCreate(Activity.java:5104)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
0622 21:01:26.001: E/AndroidRuntime(13621): ... 11 more
0622 21:01:26.001: E/AndroidRuntime(13621): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
0622 21:01:26.001: E/AndroidRuntime(13621): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
0622 21:01:26.001: E/AndroidRuntime(13621): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
0622 21:01:26.001: E/AndroidRuntime(13621): ... 20 more

Here is the layout XML
<fragment
I'm not sure if you can have a fragment as the root of your layout as fragments are supposed to be pieces that are put in another layout and exchanged.
Have you tried putting your fragment in a FrameLayout and see if it still crashes?

Your min sdk is 11. I guess you can make it 12 and use MapFragment.
To know why check the link http://developer.android.com/about/dashboards/index.html.
In that case (minsdk is 12 or above) you can extend Activity
GoogleMap mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Also import
import com.google.android.gms.maps.MapFragment;
Or
You should use Support Fragment.
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Your activity must extend FragmentActivity
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap();
Make sure you have added support library
Also make sure you imported the below
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;

Related

Android Google Map error, Unable to start activity ComponentInfo

I have tried a small example in Google map. I have got the API key but when I run the project, it displays the following errors. I have also imported Google play services.
My XML file
<?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.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
My Java
package com.arun.maps;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class GoogleMapS extends FragmentActivity {
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.google_map);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.google_map, menu);
return true;
}
}
Android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arun.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.arun.maps.GoogleMapS"
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="
AIzaSyBn3b2eGABl1JL-xXKe1H_uf4UtPRUUAwY" />
</application>
</manifest>
Error:
04-02 17:21:39.355: E/AndroidRuntime(719): FATAL EXCEPTION: main
04-02 17:21:39.355: E/AndroidRuntime(719): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arun.maps/com.arun.maps.GoogleMapS}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.os.Looper.loop(Looper.java:130)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-02 17:21:39.355: E/AndroidRuntime(719): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 17:21:39.355: E/AndroidRuntime(719): at java.lang.reflect.Method.invoke(Method.java:507)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-02 17:21:39.355: E/AndroidRuntime(719): at dalvik.system.NativeStart.main(Native Method)
04-02 17:21:39.355: E/AndroidRuntime(719): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-02 17:21:39.355: E/AndroidRuntime(719): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.Activity.setContentView(Activity.java:1657)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.arun.maps.GoogleMapS.onCreate(GoogleMapS.java:16)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-02 17:21:39.355: E/AndroidRuntime(719): ... 11 more
04-02 17:21:39.355: E/AndroidRuntime(719): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.maps.internal.q.B(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.maps.internal.q.A(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.dynamic.a.a(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
04-02 17:21:39.355: E/AndroidRuntime(719): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-02 17:21:39.355: E/AndroidRuntime(719): ... 20 more
Add this in manifest file's application tag.
<!-- Required after latest Google Play Services update -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Add this in manifest file inside your application tag:
<meta-data
android:name="com.google.android.gms.version"
android:value="4242000" />

Spinner on an ActionBar issue on a Dialog Activity

Hi I have an activity that shows a dialog form an standard layout.
android:theme="#android:style/Theme.Holo.Light.Dialog"/>
I was trying to add a simple spinner to the actionbar but I am having issues and error in the line getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST).
When I change my theme to a common activity it works perfect.
This are the errors showed by the logcat:
3114-3114/org.PeteProto E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.PeteProto/org.PeteProto.Detail}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.PeteProto.Detail.onCreate(Detail.java:30)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more

Android Map Application has stopped unexpectedly

I am working on an Android Project of using goolge map.
But when I try to run it on a tablet or HTC phone, it says the application has stopped unexpectedly. What kind of setting do I need to do, like adding library files and etc.
I have used my API key as well, so if this apps runs on a device, can I view the map or only the grid? what do we mean by signing the app?
MainActivity.java
package com.sulav.maptravis2;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends MapActivity {
MapView map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
map=(MapView) findViewById(R.id.mvMain);
map.setBuiltInZoomControls(true);
}
catch(Exception e){}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/mvMain"
android:apiKey="AIzaSyBxPKfOUpiOK981HFNcXi6szt0Dn__tQko"
/>
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sulav.maptravis2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name="com.sulav.maptravis2.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>
</application>
</manifest>
logcat output:
05-24 12:06:46.285: I/dalvikvm(7686): Could not find method android.security.MessageDigest.getInstance, referenced from method com.google.android.maps.KeyHelper.getSignatureFingerprint
05-24 12:06:46.285: W/dalvikvm(7686): VFY: unable to resolve static method 153: Landroid/security/MessageDigest;.getInstance (Ljava/lang/String;)Landroid/security/MessageDigest;
05-24 12:06:46.285: D/dalvikvm(7686): VFY: replacing opcode 0x71 at 0x0038
05-24 12:06:46.295: D/AndroidRuntime(7686): Shutting down VM
05-24 12:06:46.295: W/dalvikvm(7686): threadid=1: thread exiting with uncaught exception (group=0x409fe1f8)
05-24 12:06:46.305: E/AndroidRuntime(7686): FATAL EXCEPTION: main
05-24 12:06:46.305: E/AndroidRuntime(7686): java.lang.NoClassDefFoundError: android.security.MessageDigest
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.google.android.maps.KeyHelper.getSignatureFingerprint(KeyHelper.java:60)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.google.android.maps.MapActivity.createMap(MapActivity.java:552)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.google.android.maps.MapActivity.onCreate(MapActivity.java:422)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.sulav.maptravis2.MainActivity.onCreate(MainActivity.java:13)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.Activity.performCreate(Activity.java:4465)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.os.Looper.loop(Looper.java:137)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-24 12:06:46.305: E/AndroidRuntime(7686): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 12:06:46.305: E/AndroidRuntime(7686): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-24 12:06:46.305: E/AndroidRuntime(7686): at dalvik.system.NativeStart.main(Native Method)
Not sure if you just failed to paste it in but it appears your layout is missing this at the top.
<?xml version="1.0" encoding="utf-8"?>
Regardless check this link out:
What is 'android.security.MessageDigest''?

Map not loading anymore in Android app

Ive recently generated a new api key for an android application and now it keeps crashing whenever i try to use part of the app that uses google maps.
does anybody know what the problem could be?
ive not changed any code at all it was working flawlessly before i updated the api key.
Thanks.
05-03 00:26:20.699: E/AndroidRuntime(11859): FATAL EXCEPTION: main
05-03 00:26:20.699: E/AndroidRuntime(11859): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.menuexample/com.example.menuexample.RouteViewActivity}: java.lang.NullPointerException
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.os.Looper.loop(Looper.java:137)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-03 00:26:20.699: E/AndroidRuntime(11859): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 00:26:20.699: E/AndroidRuntime(11859): at java.lang.reflect.Method.invoke(Method.java:511)
05-03 00:26:20.699: E/AndroidRuntime(11859): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-03 00:26:20.699: E/AndroidRuntime(11859): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-03 00:26:20.699: E/AndroidRuntime(11859): at dalvik.system.NativeStart.main(Native Method)
05-03 00:26:20.699: E/AndroidRuntime(11859): Caused by: java.lang.NullPointerException
05-03 00:26:20.699: E/AndroidRuntime(11859): at com.example.menuexample.RouteViewActivity.setUpMap(RouteViewActivity.java:121)
05-03 00:26:20.699: E/AndroidRuntime(11859): at com.example.menuexample.RouteViewActivity.setUpMapIfNeeded(RouteViewActivity.java:111)
05-03 00:26:20.699: E/AndroidRuntime(11859): at com.example.menuexample.RouteViewActivity.onCreate(RouteViewActivity.java:61)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.Activity.performCreate(Activity.java:5104)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-03 00:26:20.699: E/AndroidRuntime(11859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-03 00:26:20.699: E/AndroidRuntime(11859): ... 11 more
Update:
ok it seems to be a problem with the location manager (returning null) :
locMan = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locMan.getBestProvider(criteria, false);
loc = locMan.getLastKnownLocation(provider);
Manifest
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
ok its definitely my locationmanager not getting my location.
any help would be greatly appreciated. im stressing.
Can you see grids in the MapView.If yes then may be you are not getting the location.But if you are not getting that as well and your application crashes,check your manifest for the following
<uses-library android:name=”com.google.android.maps” />
getLastKnownLocation can often return null. You should be using requestLocationUpdates in that case.

google map problem in android

hi i made google map application but when i call the class in which i made th MapActivity following error are generated
AndroidRuntime FATAL EXCEPTION: main
ERROR AndroidRuntime java.lang.NoClassDefFoundError: org.me.bdn.MapDemo
936 ERROR AndroidRuntime at org.me.bdn.listdata$1.onItemClick(listdata.java:53)
936 ERROR AndroidRuntime at android.widget.AdapterView.performItemClick(AdapterView.java:284)
936 ERROR AndroidRuntime at android.widget.ListView.performItemClick(ListView.java:3382)
14:02:25.856 936 ERROR AndroidRuntime at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
14:02:25.856 936 ERROR AndroidRuntime at android.os.Handler.handleCallback(Handler.java:587)
14:02:25.856 936 ERROR AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:92)
14:02:25.856 936 ERROR AndroidRuntime at android.os.Looper.loop(Looper.java:123)
14:02:25.856 936 ERROR AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:4627)
14:02:25.856 936 ERROR AndroidRuntime at java.lang.reflect.Method.invokeNative(Native Method)
14:02:25.856 936 ERROR AndroidRuntime at java.lang.reflect.Method.invoke(Method.java:521)
14:02:25.856 936 ERROR AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
14:02:25.856 936 ERROR AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
14:02:25.856 936 ERROR AndroidRuntime at dalvik.system.NativeStart.main(Native Method)
my MapActivity class is given here
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
/**
*
* #author bhaveshn
*/
public class MapDemo extends MapActivity{
#Override
protected boolean isRouteDisplayed() {
return false;
}
#Override
protected void onCreate(Bundle vi) {
super.onCreate(vi);
setContentView(R.layout.map);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
}
i have already added the this file in menifest file
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.me.bdn">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" >
<activity android:name=".MapDemo" android:label="Map">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
Have you write this permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-library android:name="com.google.android.maps"/>

Categories

Resources