Java Android Studio应用程序在真实设备上崩溃,但在emulator上工作

Java Android Studio应用程序在真实设备上崩溃,但在emulator上工作,java,android,android-studio,debugging,Java,Android,Android Studio,Debugging,几周前我开始使用Android Studio。我已经在一个普通登录屏幕的应用程序上工作过,在模拟器上一切正常。但如果我尝试在三星Galaxy S7 Edge(Android 7.0)上运行该应用程序,该应用程序会立即崩溃 我用API23模拟了Nexus5,当我用API24模拟像素尝试它时,模拟器也崩溃了。所以我猜问题取决于Android版本 Logcat(我仔细检查了我正在使用的所有图像,现在这是我的新Logcat): MainActivity(LoginActivity)的xml文件: 降低

几周前我开始使用Android Studio。我已经在一个普通登录屏幕的应用程序上工作过,在模拟器上一切正常。但如果我尝试在三星Galaxy S7 Edge(Android 7.0)上运行该应用程序,该应用程序会立即崩溃

我用API23模拟了Nexus5,当我用API24模拟像素尝试它时,模拟器也崩溃了。所以我猜问题取决于Android版本

Logcat(我仔细检查了我正在使用的所有图像,现在这是我的新Logcat):

MainActivity(LoginActivity)的xml文件:



降低背景文件的分辨率。现在一切都像一个符咒

您提到您正在使用尺寸为1500 x 2668英寸的图像。如logcat所示,Android正在使用
BitmapFactory
来放大此图像,而位图会根据图像尺寸占用内存。在您的情况下,这是一个内存量,超过了设备可用于您的应用程序的容量,因此
OutOfMemoryException


在不影响质量的情况下,尽可能缩小
@drawable/loginbg
的尺寸。我建议阅读关于如何使用不同尺寸的图像支持多种屏幕尺寸的书籍:

同意国防部的回答,但我想稍微扩展一下。
如果不需要透明度,请使用JPG,并且在创建位图时,选择不需要透明度甚至更少位计数的选项。

转到Styles.xml并将第一行更改为:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">


这样,就没有更多的标题栏,您就可以全屏显示了。

您必须先检查设备、项目或实际设备的Api级别是否与Api级别匹配,然后再运行。

您可以发布日志猫关于崩溃的输出吗?它应该以
E/
开头,并包含由
引起的短语
。您的模拟器是否也运行7.0?请确保您使用的是最新版本的SDK Tools package,如果问题仍然存在,请发布工具的版本。调试控制台确实不有趣,您需要的是logcat输出,可以在Android Studio底部的“Android monitor”选项卡中找到。在那里查找异常。请尝试从扩展LoginActivityAppCompatActivity@Mario您知道什么是Logcat,以及如何使用它来查找stacktrace吗?如果没有,谷歌logcat并触发崩溃,将logcat的stacktrace添加到问题中。我已经使用了本文的建议,现在它就像一个符咒!我还有最后一个问题:我正在使用这个requestWindowFeature(Window.FEATURE\u NO\u TITLE);删除我的主要活动的标题栏。在模拟器上,它运行良好,但在我的S7上,标题栏仍然存在。你知道如何解决这个问题吗?我不知道android设备会如此倾向于使用中等大小的文件。总的来说,我的背景总大小约为400 kb,但这足以让应用程序崩溃。我发现自己使用的是三星设备,这些设备的定制Android KitKat版本没有正确实现垃圾收集。你能详细介绍一下这个答案吗?
Android Emulator: 26.0.0
Android SDK Platform-Tools: 25.0.4
Android SDK Tools: 26.0.0
Google Play services, rev 39: 39.0.0
Google USB Driver, rev 11: 11.0.0
Google Web driver: 2
Intel x86 Emulator Accelerator (HAXM installer): 6.0.5
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:background="@drawable/loginbg">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/rect"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true">


    </LinearLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/signup_input_layout_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="300dp"
        android:layout_marginLeft="30dp">


    <EditText
        android:id="@+id/etUsername"
        android:layout_width="222dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textColor="#000"
        android:fontFamily="Montserrat"
        android:textSize="16dp"
        android:hint="BENUTZERNAME" />
    </android.support.design.widget.TextInputLayout>


    <android.support.design.widget.TextInputLayout
        android:id="@+id/signup_input_layout_pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_below="@id/signup_input_layout_name">

        <EditText
            android:id="@+id/etPassword"
            android:layout_width="223dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:fontFamily="Montserrat"
            android:hint="PASSWORT"
            android:inputType="textPassword"
            android:textColor="#000"
            android:textSize="16dp" />
    </android.support.design.widget.TextInputLayout>

    <ImageButton
        android:id="@+id/bSignIn"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:background="@null"
        android:layout_marginBottom="60dp"
        android:layout_marginLeft="260dp"
        android:fontFamily="Montserrat"
        android:scaleType="fitXY"
        android:src="@drawable/loginbutton"
        android:text="Login" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="NEUER ACCOUNT"
        android:id="@+id/tvRegisterLink"
        android:textSize="12sp"
        android:textColor="#B2B2B2"
        android:fontFamily="Montserrat"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="20dp"
        android:layout_alignStart="@+id/signup_input_layout_pass" />

</RelativeLayout>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">