android - 应用程序在 setContentView android 上崩溃,没有堆栈跟踪

标签 android android-layout android-manifest build.gradle

应用程序在我的手机 samsung Galaxy s4 android 5.0 custom 中执行行 setContentView(R.layout.activity_main); 时崩溃,它工作正常。但我尝试了其他 3 部(android 4.0+)手机,bluestack it 应用程序崩溃了。

我无法跟踪我的应用程序中的错误。没有异常的堆栈跟踪,应用程序只是崩溃并默默关闭。 任何帮助!

问题不在于布局文件,因为它仅在我的手机上运行良好。

布局是抽屉布局并使用 fragment 。

这里是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'
}

这是 list 文件。

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

这里是activity_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);
 }
}

最佳答案

我找到了解决方案。我刚刚从 nav_header_main.xml

中删除了 ImageView
<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 出了什么问题, 或者缺少任何东西。

关于android - 应用程序在 setContentView android 上崩溃,没有堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36923700/

相关文章:

android - Jetpack 撰写 : Performance problem when element with GlideImage is clickable in LazyColumn

android - 如何隐藏 EditText 的文本选择处理程序的 ActionPopupWindow

android - 如何在约束布局中创建更小的按钮

java - 在android中实现保存按钮

android - 未发现启动器 Activity 错误

java - Firestore 根据喜欢来订购集合

javascript - 点击时 HTML5/Android 覆盖

从未决 Intent 接收广播的Android问题

android - 当 Api 级别为 24 时,文本颜色在 xml 中不起作用

Android - 编辑 list 以禁用组件后,它将始终被禁用