I am trying to diaplay a google map in a thumbnail sized dialog box using DialogFragment
.
But i get the following eroor :- Binary file XML line #25: Error inflating class fragment
and the application crashes as soon as it starts. I searched a lot of questions in SO but was unable to find a solution.
This is my code:-
Main XMl file:-
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Spinner
android:id="@+id/spr_place_type"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentTop="true" />
<Button
android:id="@+id/btn_find"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/spr_place_type"
android:text="@string/str_btn_find" />
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/spr_place_type"
/>
</RelativeLayout>
Java class:-
public class PlaceDialogFragment extends android.support.v4.app.DialogFragment
{
@Override
public void onCreate(Bundle savedInstanceState)
{
// For retaining the fragment on screen rotation
setRetainInstance(true);
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.dialog_layout, container, false);
MapView m = (MapView) v.findViewById(R.id.map);
m.onCreate(savedInstanceState);
// Getting reference to ViewFlipper
mFlipper = (ViewFlipper) v.findViewById(R.id.flipper);
// Getting reference to TextView to display photo count
mTVPhotosCount = (TextView) v.findViewById(R.id.tv_photos_count);
// Getting reference to TextView to display place vicinity
mTVVicinity = (TextView) v.findViewById(R.id.tv_vicinity);
if(mPlace!=null){
// Setting the title for the Dialog Fragment
getDialog().setTitle(mPlace.mPlaceName);
// Array of references of the photos
Photo[] photos = mPlace.mPhotos;
// Setting Photos count
mTVPhotosCount.setText("Photos available : " + photos.length);
// Setting the vicinity of the place
mTVVicinity.setText(mPlace.mVicinity);
// Creating an array of ImageDownloadTask to download photos
ImageDownloadTask[] imageDownloadTask = new ImageDownloadTask[photos.length];
}
mainActivity.java
SupportMapFragment fragment = ( SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Getting Google Map
mGoogleMap = fragment.getMap();
// Enabling MyLocation in Google Map
mGoogleMap.setMyLocationEnabled(true);
Error:-
01-09 13:33:00.509: E/AndroidRuntime(8393): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.locations/com.example.locations.MainActivity}: java.lang.NullPointerException
01-09 13:33:00.509: E/AndroidRuntime(8393): Caused by: java.lang.NullPointerException 01-09 13:33:00.509: E/AndroidRuntime(8393): at com.example.locations.MainActivity.onCreate(MainActivity.java:119)