Skip to main content
se añadieron 5216 caracteres en el cuerpo
Origen Enlace
Tehz
  • 897
  • 2
  • 12
  • 29

aqui esta mi logcat

09-25 17:23:47.061 4207-4207/com.ciclomapp.ciclomapp.ciclomapp D/AndroidRuntime: Shutting down VM
09-25 17:23:47.069 4207-4207/com.ciclomapp.ciclomapp.ciclomapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: com.ciclomapp.ciclomapp.ciclomapp, PID: 4207
                                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ciclomapp.ciclomapp.ciclomapp/com.ciclomapp.ciclomapp.ciclomapp.MainActivity}: java.lang.NullPointerException: CameraUpdateFactory is not initialized
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:156)
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                     at android.os.Looper.loop(Looper.java:211)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5371)
                                                                                     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:945)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
                                                                                  Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
                                                                                     at com.google.android.gms.common.internal.o.b(Unknown Source)
                                                                                     at com.google.android.gms.maps.CameraUpdateFactory.mp(Unknown Source)
                                                                                     at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source)
                                                                                     at com.ciclomapp.ciclomapp.ciclomapp.MainActivity.onCreate(MainActivity.java:73)
                                                                                     at android.app.Activity.performCreate(Activity.java:5990)
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442) 
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:156) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                     at android.os.Looper.loop(Looper.java:211) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5371) 
                                                                                     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:945) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)

aqui esta mi logcat

09-25 17:23:47.061 4207-4207/com.ciclomapp.ciclomapp.ciclomapp D/AndroidRuntime: Shutting down VM
09-25 17:23:47.069 4207-4207/com.ciclomapp.ciclomapp.ciclomapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: com.ciclomapp.ciclomapp.ciclomapp, PID: 4207
                                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ciclomapp.ciclomapp.ciclomapp/com.ciclomapp.ciclomapp.ciclomapp.MainActivity}: java.lang.NullPointerException: CameraUpdateFactory is not initialized
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:156)
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                     at android.os.Looper.loop(Looper.java:211)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5371)
                                                                                     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:945)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
                                                                                  Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
                                                                                     at com.google.android.gms.common.internal.o.b(Unknown Source)
                                                                                     at com.google.android.gms.maps.CameraUpdateFactory.mp(Unknown Source)
                                                                                     at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source)
                                                                                     at com.ciclomapp.ciclomapp.ciclomapp.MainActivity.onCreate(MainActivity.java:73)
                                                                                     at android.app.Activity.performCreate(Activity.java:5990)
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442) 
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:156) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                     at android.os.Looper.loop(Looper.java:211) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5371) 
                                                                                     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:945) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
Por favor, no uses la etiqueta <i> en el código, ya que confunde a quienes leen sin saber por qué se ve así el código
Origen Enlace
Mariano
  • 24.5k
  • 20
  • 76
  • 105

es mi primera vez que trabajo con mapas y meMe gustaría hacer que mi mapa se iniciara en una ciudad, por ejemplo que al abrirlo iniciara en new york, cabe. Cabe destacar que ocupe un MapView y este el código que tengo en el método onCreateonCreate:

GoogleMap map;
MapView vista;


@Override
protected void onResume() {
    super.onResume();
    vista.onResume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    vista.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    vista.onPause();
}


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //Map creation
    vista = (MapView) findViewById(R.id.MapaPrincipal);
    vista.onCreate(savedInstanceState);
    map = vista.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    map.setMyLocationEnabled(true);

    //Start Point of the Map
    LatLng latLng = new LatLng(-33.4523007, -70.657779);
    CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(latLng,15);
    map.animateCamera(camera);

}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    boolean FragmentTransaction= false;
    Fragment fragment= null;

    if (id == R.id.AgregarRuta) {
        // Handle the camera action
    } else if (id == R.id.ValorarRuta) {
        fragment = new Valorar();
        FragmentTransaction= true;

    } else if (id == R.id.ReportarRuta) {

    } else if (id == R.id.Eventos) {

    } else if (id == R.id.Refresco) {

    } else if (id == R.id.Leyes) {

    }

    if(FragmentTransaction){

        getSupportFragmentManager().beginTransaction().replace(R.id.content_main, fragment).addToBackStack(null).commit();
        item.setChecked(true);
        getSupportActionBar().setTitle(item.getTitle());
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}

}

GoogleMap map;
MapView vista;


@Override
protected void onResume() {
    super.onResume();
    vista.onResume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    vista.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    vista.onPause();
}


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //Map creation
    vista = (MapView) findViewById(R.id.MapaPrincipal);
    vista.onCreate(savedInstanceState);
    map = vista.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    map.setMyLocationEnabled(true);

    //Start Point of the Map
    LatLng latLng = new LatLng(-33.4523007, -70.657779);
    CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(latLng,15);
    map.animateCamera(camera);

}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    boolean FragmentTransaction= false;
    Fragment fragment= null;

    if (id == R.id.AgregarRuta) {
        // Handle the camera action
    } else if (id == R.id.ValorarRuta) {
        fragment = new Valorar();
        FragmentTransaction= true;

    } else if (id == R.id.ReportarRuta) {

    } else if (id == R.id.Eventos) {

    } else if (id == R.id.Refresco) {

    } else if (id == R.id.Leyes) {

    }

    if(FragmentTransaction){

        getSupportFragmentManager().beginTransaction().replace(R.id.content_main, fragment).addToBackStack(null).commit();
        item.setChecked(true);
        getSupportActionBar().setTitle(item.getTitle());
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}
}

es mi primera vez que trabajo con mapas y me gustaría hacer que mi mapa se iniciara en una ciudad, por ejemplo que al abrirlo iniciara en new york, cabe destacar que ocupe un MapView y este el código que tengo en el método onCreate:

GoogleMap map;
MapView vista;


@Override
protected void onResume() {
    super.onResume();
    vista.onResume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    vista.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    vista.onPause();
}


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //Map creation
    vista = (MapView) findViewById(R.id.MapaPrincipal);
    vista.onCreate(savedInstanceState);
    map = vista.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    map.setMyLocationEnabled(true);

    //Start Point of the Map
    LatLng latLng = new LatLng(-33.4523007, -70.657779);
    CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(latLng,15);
    map.animateCamera(camera);

}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    boolean FragmentTransaction= false;
    Fragment fragment= null;

    if (id == R.id.AgregarRuta) {
        // Handle the camera action
    } else if (id == R.id.ValorarRuta) {
        fragment = new Valorar();
        FragmentTransaction= true;

    } else if (id == R.id.ReportarRuta) {

    } else if (id == R.id.Eventos) {

    } else if (id == R.id.Refresco) {

    } else if (id == R.id.Leyes) {

    }

    if(FragmentTransaction){

        getSupportFragmentManager().beginTransaction().replace(R.id.content_main, fragment).addToBackStack(null).commit();
        item.setChecked(true);
        getSupportActionBar().setTitle(item.getTitle());
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}

}

Me gustaría hacer que mi mapa se iniciara en una ciudad, por ejemplo que al abrirlo iniciara en new york. Cabe destacar que ocupe un MapView y este el código que tengo en el método onCreate:

GoogleMap map;
MapView vista;


@Override
protected void onResume() {
    super.onResume();
    vista.onResume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    vista.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    vista.onPause();
}


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //Map creation
    vista = (MapView) findViewById(R.id.MapaPrincipal);
    vista.onCreate(savedInstanceState);
    map = vista.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    map.setMyLocationEnabled(true);

    //Start Point of the Map
    LatLng latLng = new LatLng(-33.4523007, -70.657779);
    CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(latLng,15);
    map.animateCamera(camera);

}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    boolean FragmentTransaction= false;
    Fragment fragment= null;

    if (id == R.id.AgregarRuta) {
        // Handle the camera action
    } else if (id == R.id.ValorarRuta) {
        fragment = new Valorar();
        FragmentTransaction= true;

    } else if (id == R.id.ReportarRuta) {

    } else if (id == R.id.Eventos) {

    } else if (id == R.id.Refresco) {

    } else if (id == R.id.Leyes) {

    }

    if(FragmentTransaction){

        getSupportFragmentManager().beginTransaction().replace(R.id.content_main, fragment).addToBackStack(null).commit();
        item.setChecked(true);
        getSupportActionBar().setTitle(item.getTitle());
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}
}
Origen Enlace
Tehz
  • 897
  • 2
  • 12
  • 29

Establecer punto de partida en un mapa

es mi primera vez que trabajo con mapas y me gustaría hacer que mi mapa se iniciara en una ciudad, por ejemplo que al abrirlo iniciara en new york, cabe destacar que ocupe un MapView y este el código que tengo en el método onCreate:

GoogleMap map;
MapView vista;


@Override
protected void onResume() {
    super.onResume();
    vista.onResume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    vista.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    vista.onPause();
}


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //Map creation
    vista = (MapView) findViewById(R.id.MapaPrincipal);
    vista.onCreate(savedInstanceState);
    map = vista.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    map.setMyLocationEnabled(true);

    //Start Point of the Map
    LatLng latLng = new LatLng(-33.4523007, -70.657779);
    CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(latLng,15);
    map.animateCamera(camera);

}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    boolean FragmentTransaction= false;
    Fragment fragment= null;

    if (id == R.id.AgregarRuta) {
        // Handle the camera action
    } else if (id == R.id.ValorarRuta) {
        fragment = new Valorar();
        FragmentTransaction= true;

    } else if (id == R.id.ReportarRuta) {

    } else if (id == R.id.Eventos) {

    } else if (id == R.id.Refresco) {

    } else if (id == R.id.Leyes) {

    }

    if(FragmentTransaction){

        getSupportFragmentManager().beginTransaction().replace(R.id.content_main, fragment).addToBackStack(null).commit();
        item.setChecked(true);
        getSupportActionBar().setTitle(item.getTitle());
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}

}