Reputation: 95
Hi guys i have developer my app... but when i run my app on android 2.x crash it! It contains Google map. On android 4.x it works fine.. Can you help me please? i don't understand this problem.. I have installed Google play service from SDK. The problem is only 2.x Logcat:
05-17 14:55:49.551: W/dalvikvm(740): VFY: unable to resolve virtual method 21: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
05-17 14:55:49.551: D/dalvikvm(740): VFY: replacing opcode 0x6e at 0x0023
05-17 14:55:49.551: D/dalvikvm(740): VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z
05-17 14:55:49.565: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.575: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.581: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.581: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.581: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.599: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.605: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.611: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.611: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.637: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.647: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.651: D/AndroidRuntime(740): Shutting down VM
05-17 14:55:49.651: W/dalvikvm(740): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-17 14:55:49.661: E/AndroidRuntime(740): FATAL EXCEPTION: main
05-17 14:55:49.661: E/AndroidRuntime(740): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gianni.g/com.gianni.g.Contatti}: java.lang.NullPointerException: CameraUpdateFactory is not initialized
05-17 14:55:49.661: E/AndroidRuntime(740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.os.Looper.loop(Looper.java:130)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-17 14:55:49.661: E/AndroidRuntime(740): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 14:55:49.661: E/AndroidRuntime(740): at java.lang.reflect.Method.invoke(Method.java:507)
05-17 14:55:49.661: E/AndroidRuntime(740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-17 14:55:49.661: E/AndroidRuntime(740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-17 14:55:49.661: E/AndroidRuntime(740): at dalvik.system.NativeStart.main(Native Method)
05-17 14:55:49.661: E/AndroidRuntime(740): Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
05-17 14:55:49.661: E/AndroidRuntime(740): at com.google.android.gms.internal.er.b(Unknown Source)
05-17 14:55:49.661: E/AndroidRuntime(740): at com.google.android.gms.maps.CameraUpdateFactory.gL(Unknown Source)
05-17 14:55:49.661: E/AndroidRuntime(740): at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source)
05-17 14:55:49.661: E/AndroidRuntime(740): at com.gianni.g.Contatti.onCreate(Contatti.java:29)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-17 14:55:49.661: E/AndroidRuntime(740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-17 14:55:49.661: E/AndroidRuntime(740): ... 11 more
Contatti.java
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
public class Contatti extends FragmentActivity{
private final LatLng STARTING_POINT=new LatLng(x, x);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contatti);
Button btnNavigator = (Button) findViewById(R.id.btnNavigator);
GoogleMap map=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.moveCamera(CameraUpdateFactory.newLatLngZoom(STARTING_POINT, 5));
map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
map.addMarker(new MarkerOptions().position(STARTING_POINT));
btnNavigator.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String uri = "http://maps.google.com/maps?&daddr="+"36.997646, 14.607422";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
}
});
}
contatti.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_span="6"
android:gravity="center"
android:text="Telefono: +39 s"
android:textSize="18sp"
android:textStyle="bold" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_span="6"
android:gravity="center"
android:text=" a"
android:textSize="15sp"
android:textStyle="italic" >
</TextView>
</TableRow>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="@dimen/GMapsBottom"
android:paddingLeft="@dimen/GMapsHorizontal"
android:paddingRight="@dimen/GMapsHorizontal"
android:paddingTop="@dimen/GMapsTop" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>
</TableLayout>
<Button
android:id="@+id/btnNavigator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:layout_marginTop="5dp"
android:text="Avvia Navigatore" />
</RelativeLayout>
Upvotes: 0
Views: 255
Reputation: 13223
From the logcat is evident what the problem is:
05-17 14:55:49.565: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.575: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.581: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.581: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.581: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.599: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.605: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.611: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.611: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.637: W/GooglePlayServicesUtil(740): Google Play services is missing.
05-17 14:55:49.647: W/GooglePlayServicesUtil(740): Google Play services is missing.
You need to make sure you have code that checks to see if Google Play Services are installed in the device. If they are not, you should direct the user to install them.
Upvotes: 1
Reputation: 2181
You cant use the same Fragment for Android >4.0 and Android <4.0 ! You have to use a Fragment from the Support v4 library and the SupportFragmentManager!
Upvotes: 1