Android : Runtime error in GoogleMap app

on Monday, March 23, 2015


I am writing an app with GoogleMaps. I run it on emulator now. The layout below works good. I would like to have some additional TextViews and buttons on the screen with the map. But I have runtime error, if I add second TextView or button to my XML. If I add them inside of some LinearLayout, I also get error.



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/backNormal"
android:orientation="vertical"
>
<TextView
android:id="@+id/mytext2"
android:gravity="center"
android:text='My Text'
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/text_style_title"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@color/backNormal"
android:orientation="vertical"
>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>


Error text is below:



3459-3459/moorlakgames.packet1 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: moorlakgames.packet1, PID: 3459
java.lang.RuntimeException: Unable to start activity ComponentInfo{moorlakgames.packet1/moorlakgames.packet1.MyActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.MapFragment.getMap()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.MapFragment.getMap()' on a null object reference


As I said it works with one TextView in layout. Any ideas? Thanks!


0 comments:

Post a Comment