2016-04-28 77 views
1

應用程序崩潰時,它執行行setContentView(R.layout.activity_main);在我的手機samsung galaxy s4 android 5.0自定義它工作正常。但我嘗試了3個其他的(Android 4.0+)手機和bluestack它的應用程序崩潰。應用程序崩潰setContentView android沒有堆棧跟蹤

我無法跟蹤我的應用程序中錯誤的位置。沒有堆棧跟蹤異常,應用程序剛剛崩潰並默默關閉。 任何幫助!

問題不在佈局文件中,因爲它只在我的手機上正常工作。

佈局是抽屜佈局和使用片段。

這裏是build.gradel

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

defaultConfig { 
    applicationId "com.iorzb.malik.proximity" 
    minSdkVersion 17 
    targetSdkVersion 23 
    versionCode 1 
    versionName "1.0" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.2.0' 
    compile 'com.android.support:design:23.2.0' 
    compile 'com.google.android.gms:play-services:8.1.0' 
    compile 'com.google.android.gms:play-services-location:7.5.0' 
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' 
    compile files('libs/your jar volley.jar') 
    compile 'com.google.code.gson:gson:2.6.2' 
} 

這裏是清單文件。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.iorzb.malik.proximity" 
    android:versionCode="1" 
    android:versionName="1.0"> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

<application 
    android:name=".Help.AppController" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:largeHeap="true" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MainActivity" 
     android:configChanges="orientation|keyboardHidden" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 



</application> 

這裏是actvity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout `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:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:id="@+id/container_body" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 


    </LinearLayout> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

這裏是app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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" 
    android:fitsSystemWindows="true" 
    tools:context="com.iorzb.malik.proximity.MainActivity"> 
    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
    </android.support.design.widget.AppBarLayout> 
    <include layout="@layout/content_main" /> 
</android.support.design.widget.CoordinatorLayout> 

這裏是nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/nav_header_height" 
    android:background="@drawable/side_nav_bar" 
    android:gravity="bottom" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:background="@drawable/round_corner" 
     android:layout_marginTop="20dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:src="@drawable/logo_proximity" /> 

</LinearLayout> 

這裏isactivity_main_drawer.xml(導航菜單)

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

    <group android:checkableBehavior="single"> 
     <item 
      android:id="@+id/nav_home" 
      android:icon="@mipmap/ic_home_black_36dp" 
      android:title="Home" /> 
     <item 
      android:id="@+id/nav_map" 
      android:icon="@mipmap/ic_directions_car_black_36dp" 
      android:title="Driving Directions" /> 
     <item 
      android:id="@+id/nav_my_stores" 
      android:icon="@mipmap/ic_shopping_cart_black_36dp" 
      android:title="My Stores" /> 
     <item 
      android:id="@+id/nav_new_stores" 
      android:icon="@drawable/signup_icon" 
      android:title="New Stores" /> 
    </group> 


</menu> 

這裏是MainActivity.class

public class MainActivity extends AppCompatActivity{ 

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

你應該發佈你的XML佈局和你的活動代碼。如果它適用於android 5.0並不意味着您的佈局xml是無bug的 –

+0

應用程序不會在沒有logcat報告的情況下崩潰。也許你錯過了一些東西。 –

+0

我在這裏添加了xml和java代碼。感謝您的迴應。 –

回答

1

我得到了解決方案。我只是刪除了圖像視圖從nav_header_main.xml

<ImageView 
    android:id="@+id/imageView" 
    android:background="@drawable/round_corner" 
    android:layout_marginTop="20dp" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="fitXY" 
    android:paddingTop="@dimen/nav_header_vertical_spacing" 
    android:src="@drawable/logo_proximity" /> 

它工作得很好。我不知道如何,但它的工作。任何人可以告訴這個imageview有什麼不對, 或任何東西丟失。

+0

問題是用行中的drawable xml android:background =「@ drawable/round_corner」 –

0

這個問題在谷歌圖書館。

compile 'com.android.support:appcompat-v7:23.2.0' 
compile 'com.android.support:design:23.2.0' 

請刪除所有V7:23.2.0並安裝anyother.Your代碼自動工作。 只需更改

compile 'com.android.support:appcompat-v7:23.1.1' 
compile 'com.android.support:design:23.1.1' 

希望您能解決您的問題。

+0

我刪除了工具欄,然後嘗試但沒有運氣。 –

+0

請檢查我更新的答案,希望這會對你有所幫助。 –

相關問題