-1

Ich habe eine Tabbed-Layout-Anwendung und der dritte Tab hat Google Maps implementiert, keine Code-Fehler, aber wenn ich im Emulator starten es nicht einmal es nur sagt, dass es gestoppt wurdeAnwendung wird nicht gestartet, aber keine Fehler in Code

hier ist meine Haupttätigkeit Klasse

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

    } 

hier ist meine Tätigkeit Haupt 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> 

hier meine Karte Fragment Klasse ist

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(); 
} 
} 

hier ist mein Fragment Karte XML-Datei

<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" 
/> 

hier ist meine Heimat Fragment Klasse

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; 

} 
} 

hier ist mein Zuhause Fragment 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> 

hier ist meine Rufe Fragmentklasse

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; 

} 
} 

hier ist meine Rufe XML-Datei

<?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> 

hier ist mein 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

Ihre logcat Ausgang – Zielony

+0

Post ive eingefügt es in die ursprüngliche Frage @ Zielony –

+0

@AlexanderRufus Versuchen Sie zuerst diese http://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor fügen Sie dies hinzu Zeile false in Ihrer styles.xml – Raghavendra

Antwort

0

Ihre logcat Ausgabe Ihnen genau sagt, was passiert ist und wie es zu beheben:

Diese Aktivität hat bereits eine Aktionsleiste von der Fensterdekoration geliefert. Fordern Sie nicht Window.FEATURE_SUPPORT_ACTION_BAR an und setzen Sie windowActionBar in auf false, um stattdessen eine Toolbar zu verwenden.

ich auf Design-Einstellungen setzen würde:

Verwenden der Symbolleiste ein ActionBar zu ersetzen ist ziemlich geradlinig und beginnt mit dafür sorgen, dass die Aktivität ActionBarActivity erstreckt. Stellen Sie außerdem sicher, dass das Thema für diese Aktivität ein Kind von Theme.AppCompat.NoActionBar oder Theme.AppCompat.Light.NoActionBar ist. Wenn Sie nicht die verwenden Theme.AppCompat Varianten können Sie alternativ die folgenden Zeilen zu Ihrem Thema hinzufügen:

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

den ganzen Artikel finden Sie hier: http://mrengineer13.com/how-to-use-toolbar-to-replace-your-actionbar/

+0

danke, aber ich kann nicht sehen, wo das auf True gesetzt ist @Zielony –

+0

vielen Dank, ich bin nur verwirrt durch den Artikel Namen Zeilen oben, wo genau sollen sie gehen? –

Verwandte Themen