-1

J'ai une application de mise en page à onglets et le troisième onglet a Google Maps implémenté, pas d'erreurs de code mais quand je commence dans l'émulateur, il ne démarre même pas il indique qu'il a été arrêtél'application ne démarre pas mais aucune erreur dans le code

ici est ma principale classe d'activité

public class MainActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    // Get the ViewPager and set it's PagerAdapter so that it can display items 
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); 
    PagerAdapter pagerAdapter = 
      new PagerAdapter(getSupportFragmentManager(), MainActivity.this); 
    viewPager.setAdapter(pagerAdapter); 

    // Give the TabLayout the ViewPager 
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); 
    tabLayout.setupWithViewPager(viewPager); 

    // Iterate over all tabs and set the custom view 
    for (int i = 0; i < tabLayout.getTabCount(); i++) { 
     TabLayout.Tab tab = tabLayout.getTabAt(i); 
     tab.setCustomView(pagerAdapter.getTabView(i)); 
    } 
} 

class PagerAdapter extends FragmentPagerAdapter { 

    String tabTitles[] = new String[] { "Home", "Shouts", "Maps", }; 
    Context context; 

    public PagerAdapter(FragmentManager fm, Context context) { 
     super(fm); 
     this.context = context; 
    } 

    @Override 
    public int getCount() { 
     return tabTitles.length; 
    } 

    @Override 
    public Fragment getItem(int position) { 

     switch (position) { 
      case 0: 
       return new HomeFragment(); 
      case 1: 
       return new ShoutsFragment(); 
      case 2: 
       return new MapFragment(); 
     } 

     return null; 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     // Generate title based on item position 
     return tabTitles[position]; 
    } 

    public View getTabView(int position) { 
     View tab = LayoutInflater.from(MainActivity.this).inflate(R.layout.mapfragment, null); 
     TextView tv = (TextView) tab.findViewById(R.id.map); 
     tv.setText(tabTitles[position]); 
     return tab; 
    } 

    } 

ici est mon activité principale xml

<RelativeLayout 
android:id="@+id/main_layout" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:background="?attr/colorPrimary" 
    android:elevation="6dp" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

<android.support.design.widget.TabLayout 
    android:id="@+id/tab_layout" 
    app:tabMode="fixed" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/toolbar" 
    android:background="?attr/colorPrimary" 
    android:elevation="6dp" 
    app:tabTextColor="#d3d3d3" 
    app:tabSelectedTextColor="#ffffff" 
    app:tabIndicatorColor="#ff00ff" 
    android:minHeight="?attr/actionBarSize" 
    /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@id/tab_layout"/> 

</RelativeLayout> 

voici ma carte classe fragment

public class MapFragment extends Fragment { 

MapView mMapView; 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // inflate and return the layout 
    View v = inflater.inflate(R.layout.mapfragment, container, 
      false); 
    mMapView = (MapView) v.findViewById(R.id.map); 
    mMapView.onCreate(savedInstanceState); 

    mMapView.onResume();// needed to get the map to display immediately 

    try { 
     MapsInitializer.initialize(getActivity().getApplicationContext()); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    SupportMapFragment supportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); 
    supportMapFragment.getMapAsync((OnMapReadyCallback) this); 
    // latitude and longitude 
    double latitude = 17.385044; 
    double longitude = 78.486671; 

    // create marker 
    MarkerOptions marker = new MarkerOptions().position(
      new LatLng(latitude, longitude)).title("Hello Maps"); 

    // Changing marker icon 
    marker.icon(BitmapDescriptorFactory 
      .defaultMarker(BitmapDescriptorFactory.HUE_ROSE)); 



    // Perform any camera updates here 
    return v; 
} 

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

@Override 
public void onPause() { 
    super.onPause(); 
    mMapView.onPause(); 
} 

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

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

Voici ma carte fragment fichier xml

<fragment 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_weight="2" 
android:name="com.google.android.gms.maps.SupportMapFragment" 
android:id="@+id/map" 
xmlns:android="http://schemas.android.com/apk/res/android" 
/> 

ici est mon fragment maison classe

public class HomeFragment extends Fragment{ 

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Get the view from fragment home.xml 
    View view = inflater.inflate(R.layout.home_fragment, container, false); 
    return view; 

} 
} 

ici est mon ici fragment maison xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<TextView 
    android:id="@+id/custom_text" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:textSize="16dip" 
    android:textColor="#ffffff" 
    android:singleLine="true" 
    /> 
</LinearLayout> 

est mes cris classe de fragment

public class ShoutsFragment extends Fragment{ 

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Get the view from fragment home.xml 
    View view = inflater.inflate(R.layout.shouts_fragment, container, false); 
    return view; 

} 
} 

voici mon cris fichier xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<TextView 
    android:id="@+id/custom_text" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:textSize="16dip" 
    android:textColor="#ffffff" 
    android:singleLine="true" 
    /> 
</LinearLayout> 

ici est mon logcat

03-25 11:06:59.012 3016-3016/com.example.hp_user.dn_tab1 I/art: Not late-enabling -Xcheck:jni (already on) 
03-25 11:06:59.483 3016-3016/com.example.hp_user.dn_tab1 W/System:  ClassLoader referenced unknown path: /data/app/com.example.hp_user.dn_tab1- 2/lib/x86 
03-25 11:06:59.669 3016-3016/com.example.hp_user.dn_tab1 I/GMPM: App     measurement is starting up, version: 8487 
03-25 11:06:59.669 3016-3016/com.example.hp_user.dn_tab1 I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE 
03-25 11:06:59.759 3016-3016/com.example.hp_user.dn_tab1 E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin. 
03-25 11:06:59.813 3016-3016/com.example.hp_user.dn_tab1 E/GMPM: Scheduler not set. Not logging error/warn. 
03-25 11:07:00.045 3016-3040/com.example.hp_user.dn_tab1 E/GMPM: Uploading is not possible. App measurement disabled 
03-25 11:07:00.379 3016-3016/com.example.hp_user.dn_tab1 D/AndroidRuntime: Shutting down VM 
03-25 11:07:00.381 3016-3016/com.example.hp_user.dn_tab1 E/AndroidRuntime: FATAL EXCEPTION: main 
                     Process: com.example.hp_user.dn_tab1, PID: 3016 
                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hp_user.dn_tab1/com.example.hp_user.dn_tab1.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead. 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                     Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead. 
                      at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:197) 
                      at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129) 
                      at com.example.hp_user.dn_tab1.MainActivity.onCreate(MainActivity.java:27) 
                      at android.app.Activity.performCreate(Activity.java:6237) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)  
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  
                      at android.os.Handler.dispatchMessage(Handler.java:102)  
                      at android.os.Looper.loop(Looper.java:148)  
                      at android.app.ActivityThread.main(ActivityThread.java:5417)  
                      at java.lang.reflect.Method.invoke(Native Method)  
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
03-25 11:07:08.761 3016-3022/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 82.187ms 
03-25 11:07:08.772 3016-3026/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 9.588ms 
03-25 11:07:20.033 3016-3022/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 32.982ms 
03-25 11:07:24.581 3016-3022/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 91.462ms 
03-25 11:07:32.640 3016-3022/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 159.934ms 
03-25 11:07:42.053 3016-3022/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 50.217ms 
03-25 11:07:47.886 3016-3022/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 10.813ms 
03-25 11:07:50.622 3016-3022/com.example.hp_user.dn_tab1 W/art: Suspending all threads took: 331.902ms 
+0

votre sortie publier logcat – Zielony

+0

Ive inséré dans la question d'origine @ Zielony –

+0

@AlexanderRufus D'abord essayer cela http://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor ajouter ceci line false dans vos styles.xml – Raghavendra

Répondre

0

Votre sortie logcat vous dit exactement ce qui est arrivé et comment le résoudre:

Cette L'activité a déjà une barre d'action fournie par le décor de la fenêtre. Ne demandez pas Window.FEATURE_SUPPORT_ACTION_BAR et définissez windowActionBar sur false dans votre thème pour utiliser une barre d'outils à la place.

Je serais prêt à parier sur les paramètres du thème:

Utilisation de la barre d'outils pour remplacer un ActionBar est assez simple et commence par faire en sorte que l'activité s'étend ActionBarActivity. Assurez-vous également que le thème de cette activité est enfant de Theme.AppCompat.NoActionBar ou de Theme.AppCompat.Light.NoActionBar. Si vous n'utilisez pas le Theme.AppCompat variantes alors vous pouvez également ajouter les lignes à votre thème:

<item name="android:windowNoTitle">true</item> 
<item name="windowActionBar">false</item> 

Voir l'article complet ici: http://mrengineer13.com/how-to-use-toolbar-to-replace-your-actionbar/

+0

merci mais je ne peux pas voir où cela est réglé à vrai @Zielony –

+0

merci beaucoup, je suis seulement confus par les lignes de nom d'élément ci-dessus où sont-ils censés aller? –