2016-04-28 82 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

请检查我更新的答案,希望这会对你有所帮助。 –

相关问题