3

I'm new in android programming; I have that small app with 3 pages (fragments), swiping between them using pageradapter and viewpager; one of these pages contains checkbox [and other controls] and a map; my problem is that the program is crashing on start.

Fragment_compass.java

package com.ibdiab.emadaldien;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class Fragment_Compass extends Fragment {
MapView mapView;
GoogleMap map;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View v = inflater.inflate(R.layout.activity_compass, container, false);

    // Gets the MapView from the XML layout and creates it
    mapView = (MapView) v.findViewById(R.id.eamap);
    mapView.onCreate(savedInstanceState);

    // Gets to GoogleMap from the MapView and does initialization stuff
    map = mapView.getMap();
    //map.getUiSettings().setMyLocationButtonEnabled(false);
    //map.setMyLocationEnabled(true);
    map.addMarker(new MarkerOptions().position(new LatLng(50.167003,19.383262)));

    // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
    try {
        MapsInitializer.initialize(this.getActivity());
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }

    // Updates the location and zoom of the MapView
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
    map.animateCamera(cameraUpdate);

    return v;
}

@Override
public void onResume() {
    mapView.onResume();
    super.onResume();
}

@Override
public void onDestroy() {
    super.onDestroy();
    mapView.onDestroy();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mapView.onLowMemory();
}
}

activity_compass.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<CheckBox
    android:id="@+id/autolocate"

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="view live map" />

<fragment
    android:id="@+id/eamap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>

MainScr.java

public class MainScr extends FragmentActivity {


private PagerAdapter el_pagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainlayout);
    initialisePaging();     
}

private void initialisePaging() {
    // TODO Auto-generated method stub
    List<Fragment> eafragments = new Vector<Fragment>();        
    eafragments.add(Fragment.instantiate(this, Fragment_PraysTable.class.getName()));
    eafragments.add(Fragment.instantiate(this, Fragment_Main.class.getName()));
    eafragments.add(Fragment.instantiate(this, Fragment_Compass.class.getName()));
    el_pagerAdapter = new PagerAdapter(this.getSupportFragmentManager() , eafragments);
    ViewPager pager = (ViewPager) findViewById(R.id.mainviewpager);
    pager.setAdapter(el_pagerAdapter);
    pager.setCurrentItem(1);
}

@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_scr, menu);
    return true;
}

}
saravankg
  • 909
  • 1
  • 10
  • 21

0 Answers0