错误,可能与内存有关

Error, probably about memory

所以我正在测试我的应用程序,并且在一点上发生了错误,我看到了堆栈跟踪,它在一条我什至没有更改的线上,它以前工作过。但是查看堆栈跟踪我认为问题是内存不足。 这是错误行(在 setContentView.. 行中)

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_agencia_figueira);

    Button buttonFigueira = (Button) findViewById(R.id.buttonMenu);
    buttonFigueira.setOnClickListener(
            new Button.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(agenciaFigueira.this, MainActivity.class);
                    agenciaFigueira.this.startActivity(i);
                }
            }
    );

但是堆栈跟踪的其中一行是:无法分配 10603020 字节的分配,其中有 4194304 个空闲字节和 7MB,直到 OOM

如果是内存不足怎么办? :x

  1. 你绝对需要重新检查你的堆栈回溯......并可能添加调试语句......以确定你要求的 where 10MB(失败)。在确定解决方案之前,您需要确定有问题的特定资源

  2. 如果您使用的是模拟器...那么您就可以指定图像的内存大小(这在实体手机上通常是做不到的)。确保模拟器有 "reasonable" 的 RAM。 512MB 通常是一个不错的数字。

  3. Android Studio 有优秀的 工具来检查内存使用情况。例如:

https://developer.android.com/tools/debugging/debugging-memory.html

  1. 请post返回您找到的内容!