-1

运行我的应用程序后,我遇到了这个错误。

在此之前有一条错误消息:

"Out of memory on a 30720016-byte allocation."

我所有的图像都在drawable文件夹内。

这是我的代码:

package com.androidteam.sg.easy.taxi.booking;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Declare our View variables and assign them the Views from the layout file
    Button getAnswerButton = (Button) findViewById(R.id.button1);
    Button getAnswerButton1 = (Button) findViewById(R.id.button2);
    Button getAnswerButton2 = (Button) findViewById(R.id.button3);
    Button getAnswerButton3 = (Button) findViewById(R.id.button4);
    Button getAnswerButton4 = (Button) findViewById(R.id.button5);
    Button getAnswerButton5 = (Button) findViewById(R.id.button6);
    Button getAnswerButton6 = (Button) findViewById(R.id.button7);
    Button getAnswerButton7 = (Button) findViewById(R.id.button8);

    //Add PhoneStateListener
    PhoneCallListener phoneListener = new PhoneCallListener();
    TelephonyManager telephonyManager = (TelephonyManager) this
            .getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);

    getAnswerButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer by calling the number
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:65521111"));
            startActivity(intent);
        }
    });
    getAnswerButton1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer label with answer
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:65521111"));
            startActivity(intent);
        }
    });
    getAnswerButton2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer label with answer
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:6778 0808"));
            startActivity(intent);
        }
    });
    getAnswerButton3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer label with answer
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:6363 0808"));
            startActivity(intent);
        }
    });
    getAnswerButton4.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer label with answer
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:6485 7777"));
            startActivity(intent);
        }
    });
    getAnswerButton5.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer label with answer
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:6555 8888"));
            startActivity(intent);
        }
    });
    getAnswerButton6.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer label with answer
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:6555 3333"));
            startActivity(intent);
        }
    });
    getAnswerButton7.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //The button was clicked, so update the answer label with answer
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:6293 5545"));
            startActivity(intent);
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}



//monitor phone call activities

private class PhoneCallListener extends PhoneStateListener {

    private boolean isPhoneCalling = false;

    String LOG_TAG = "LOGGING 123";

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
        }

        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            // active
            Log.i(LOG_TAG, "OFFHOOK");

            isPhoneCalling = true;
        }

        if (TelephonyManager.CALL_STATE_IDLE == state) {
            // run when class initial and phone call ended, 
            // need detect flag from CALL_STATE_OFFHOOK
            Log.i(LOG_TAG, "IDLE");

            if (isPhoneCalling) {

                Log.i(LOG_TAG, "restart app");

                // restart app
                Intent i = getBaseContext().getPackageManager()
                    .getLaunchIntentForPackage(
                        getBaseContext().getPackageName());
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);

                isPhoneCalling = false;
            }

        }
    }
}


}

请如何解决错误消息。

4

1 回答 1

1

如果您的图像尺寸太大而无法放入应用程序的堆中,则会发生这种情况。android 应用程序的堆从 android 4.2 开始为 16MB。可能您的图像太大,因此它们无法放入堆内存中,并且您遇到内存不足错误。但是从代码来看,您似乎没有在代码中使用任何图像。因此,如果您尝试在应用程序中显示高质量图像,请确保在
drawable-hdpi、drawable-ldpi、drawable-xhdpi、drawable-mdpi 文件夹中也有低屏幕分辨率设备的图像。

于 2013-10-20T06:27:17.263 回答