0

我正在尝试组合一个简单的应用程序,该应用程序可以获取 sd 卡上的现有文件并将其作为备份通过电子邮件发送到内容提供商方案。有几个问题 - 最令人不安的是我不断收到这些图形缓冲区分配错误 - 看起来当尝试​​调用第二个活动时,图形缓冲区分配正在耗尽所有内存,但我不知道为什么。我已经读到在我正在测试的手机(Galaxy Nexus)上报告了这个问题的错误,但我几乎在 UI 上使用默认图形 - 这是非常基本的,所以我不确定为什么会发生这种情况. 我也是这方面的新手,所以如果我忽略了这些非常明显的东西,请原谅我。

下面是带有相关错误的代码和错误日志(由于它是周期性的且非常长,因此对其长度进行了编辑)。我感谢任何帮助和/或指导 - 谢谢。

    public class MainActivity extends Activity implements OnClickListener
{
/**
 * This class runs in the event that the Content provider
 * step fails. This looks for the existing file generated by the
 * content class, prepares the file, and hands the file
 * to the SendData class to be emailed.
 */
private static final String TAG = "MainActivity_VADataSender";
public static String MyDB;

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

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

    // Create the getData intent
    Intent intentgetData;

    // call the life cycle events
    // for now, inherit the settings from the parent class
    // replace these with specifics if necessary once program is operational
    public void onPause()
        {
        super.onPause();
        }

    public void onResume()
        {
        super.onResume();
        }

    public void onStop()
        {
        super.onStop();
        }

    public void onDestroy()
        { 
        super.onDestroy();
        }

        @Override 
        public void onStart() 
        {
            intentgetData = new Intent(MainActivity.this, SendData.class);
            startActivity(intentgetData);
        super.onStart();
        }
        public MainActivity() throws FileMissingException   
        {           
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();

            if (sd.canWrite()) 
                {
                // verify the paths-  NOTE: may be device-specific 
                String currentDBPath = "TLC_COMMON/database.txt"; 
                String backupDBPath = "database.txt"; 
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);

                if (currentDB.exists()) 
                // make the connection  
                    try
                    //set the connections
                    {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();

                    // use the actual file name here (not backupDB)
                    setMyDB(backupDB);          
                    } 
                    catch (Exception e)
                    // if connection error
                        {
                        Log.e(TAG, "ERROR 1: current database does not exist"); 
                        Toast.makeText(getBaseContext(), e.getMessage(),
                                Toast.LENGTH_SHORT).show();
                        this.finish();
                        // halt processing  
                        throw new FileMissingException();
                        } 
                }
                else
                // if sd can not write  
                    {
                    Log.e(TAG, "ERROR 2: SD is not writable");
                    //Toast.makeText(getBaseContext(), e.getMessage(),
                        //  Toast.LENGTH_SHORT).show();
                    this.finish(); 
                    throw new FileMissingException();
                    }
            // returned at line 102
            //return MyDB;
        }


        // same here- get the actual file name
    public void setMyDB(File backupDB) {
        // TODO Auto-generated method stub

    }

    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    public static Object getMyDB() {
        // TODO Auto-generated method stub
        return MyDB;
    }   
}
    </CODE>

二等:

    public class SendData extends MainActivity
{
public SendData() throws FileMissingException {
    super();
    // TODO Auto-generated constructor stub
}

private static final String TAG = "SendData_VADatasender";

/* Checks if external storage is available to read */   
public boolean isExternalStorageReadable() 
    {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) ||
        Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) 
        {
        return true;
        }
        {       
        return false;
        }
    }   

// Send data by email
    public void dataGetter() throws FileMissingException
    {
        try
        {
        File sd = Environment.getExternalStorageDirectory();
        // verify it is saving as this file name; also path in previous class
        String fileName = "MyDB";

            {
                if (sd.canWrite()) 
                    { 
                    // add the File Attachment and URI (in EXTRA_TEXT) below once the program is running
            //is this redundant to Object attachment below?
                    File attachment = new File(fileName); 
                    }   
                else 
                    {
                    Log.e(TAG, "Email attachment failed");
                    //Toast.makeText(getBaseContext(), e.getMessage(),
                            //Toast.LENGTH_SHORT).show();

                    finish();
                    }
            }
        }
        catch(Exception e)
        {
        Log.e(TAG,"ERROR 5: Could not locate file"); 
        Toast.makeText(getBaseContext(), e.getMessage(),
                Toast.LENGTH_SHORT).show();

        finish();
        throw new FileMissingException();
        }
    }

        Intent email;

        @Override
        public void onStart(){
        //Uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), MyDB));
            {
        Object attachment = MainActivity.getMyDB();

                { 
            Intent email = new Intent(Intent.ACTION_SENDTO);
            email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Exercise data");
            email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"vamedstudy@gmail.com"});
            email.putExtra(android.content.Intent.EXTRA_TEXT, (Boolean) (attachment)); //Uri.fromFile(attachment)
            //email.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse((String) attachment));
            //email.setType("message/rfc822");
            email.setType("text/plain");
            startActivity(Intent.createChooser(email, "Send the exercise data:"));  
            super.onStart();
                }
            }   
        }   

    public void finish() 
        {   
        }   
    }

ERROR LOG:

11-21 12:21:54.367: I/ActivityManager(2448): START {act=android.intent.action.MAIN cat=

[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.va.datasender/.MainActivity 

u=0} from pid 2640
11-21 12:21:54.468: E/MainActivity_VADataSender(4040): ERROR: current database does not exist
11-21 12:21:54.492: I/ActivityManager(2448): START {act=android.intent.action.CHOOSER 

cmp=android/com.android.internal.app.ChooserActivity (has extras) u=0} from pid 4040
11-21 12:21:54.500: I/ActivityManager(2448): START {cmp=com.example.va.datasender/.SendData 

u=0} from pid 4040
11-21 12:21:54.585: E/MainActivity_VADataSender(4040): ERROR: current database does not exist

....repeats...then graphics errors

11-21 12:21:57.265: I/ActivityManager(2448): START {cmp=com.example.va.datasender/.SendData 

u=0} from pid 4040
11-21 12:21:57.359: E/IMGSRV(121): :0: PVRSRVAllocDeviceMem: Error 1 returned
11-21 12:21:57.359: E/IMGSRV(121): :0: GenericAlloc: Failed to allocate device memory
11-21 12:21:57.359: W/GraphicBufferAllocator(121): alloc(720, 1184, 5, 00000b00, ...) failed -

12 (Out of memory)
11-21 12:21:57.359: D/GraphicBufferAllocator(121): Allocated buffers:
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40b0cc40: 3404.00 KiB |  720 ( 736) x 1184 

|        5 | 0x00000b00
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40b1e6d8: 3404.00 KiB |  720 ( 736) x 1184 

|        5 | 0x00000b00
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40bb5898: 3404.00 KiB |  720 ( 736) x 1184 

|        5 | 0x00000b00
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40bb5a90: 3404.00 KiB |  720 ( 736) x 1184 

|        5 | 0x00000b00
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40bb5f18: 3404.00 KiB |  720 ( 736) x 1184 

|        5 | 0x00000b00
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40bb6ec8: 3404.00 KiB |  720 ( 736) x 1184 

|        5 | 0x00000b00
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40bba990: 1213.25 KiB |  720 ( 736) x  422 

|        1 | 0x00000933
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40bbb428: 3404.00 KiB |  720 ( 736) x 1184 

|        5 | 0x00000b00
...
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40c06b58: 1279.38 KiB |  720 ( 736) x  445 

|        1 | 0x00000933
11-21 12:21:57.359: D/GraphicBufferAllocator(121): 0x40c0e778:  143.75 KiB |  720 ( 736) 
11-21 12:21:57.359: E/SurfaceFlinger(121): GraphicBufferAlloc::createGraphicBuffer(w=720, 

h=1184) failed (Out of memory), handle=0x0
11-21 12:21:57.359: E/BufferQueue(121): 

[com.example.va.datasender/com.example.va.datasender.SendData] dequeueBuffer: 

SurfaceComposer::createGraphicBuffer failed
11-21 12:21:57.359: E/IMGSRV(4040): :0: DequeueLockStoreBuffer: Failed to de-queue buffer
11-21 12:21:57.359: W/HardwareRenderer(4040): EGL error: EGL_BAD_NATIVE_WINDOW
11-21 12:21:57.375: W/HardwareRenderer(4040): Mountain View, we've had a problem here. 

Switching back to software rendering.

...then out of memory errors...

11-21 12:21:57.453: E/SurfaceFlinger(121): GraphicBufferAlloc::createGraphicBuffer(w=720, 

h=1184) failed (Out of memory), handle=0x0
11-21 12:21:57.453: E/BufferQueue(121): 

[com.example.va.datasender/com.example.va.datasender.SendData] dequeueBuffer: 

SurfaceComposer::createGraphicBuffer failed
11-21 12:21:57.453: E/IMGSRV(4040): :0: DequeueLockStoreBuffer: Failed to de-queue buffer
11-21 12:21:57.453: E/libEGL(4040): eglMakeCurrent:534 error 3003 (EGL_BAD_ALLOC)
11-21 12:21:57.460: E/ViewRootImpl(4040): OutOfResourcesException initializing HW surface
11-21 12:21:57.460: E/ViewRootImpl(4040): android.view.Surface$OutOfResourcesException: 

eglMakeCurrent failed EGL_BAD_ALLOC
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.HardwareRenderer

$GlRenderer.createEglSurface(HardwareRenderer.java:920)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.HardwareRenderer

$GlRenderer.initialize(HardwareRenderer.java:748)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.ViewRootImpl.performTraversals

(ViewRootImpl.java:1505)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.ViewRootImpl.doTraversal

(ViewRootImpl.java:998)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.ViewRootImpl

$TraversalRunnable.run(ViewRootImpl.java:4212)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.Choreographer

$CallbackRecord.run(Choreographer.java:725)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.Choreographer.doCallbacks

(Choreographer.java:555)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.Choreographer.doFrame

(Choreographer.java:525)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.view.Choreographer

$FrameDisplayEventReceiver.run(Choreographer.java:711)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.os.Handler.handleCallback

(Handler.java:615)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.os.Handler.dispatchMessage

(Handler.java:92)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.os.Looper.loop(Looper.java:137)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at android.app.ActivityThread.main

(ActivityThread.java:4745)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at java.lang.reflect.Method.invokeNative(Native 

Method)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at java.lang.reflect.Method.invoke

(Method.java:511)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at com.android.internal.os.ZygoteInit

$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at com.android.internal.os.ZygoteInit.main

(ZygoteInit.java:553)
11-21 12:21:57.460: E/ViewRootImpl(4040):   at dalvik.system.NativeStart.main(Native 

Method)
11-21 12:21:57.460: I/Process(4040): Sending signal. PID: 4040 SIG: 9
11-21 12:21:57.460: I/WindowManager(2448): Out of memory for surface!  Looking for leaks...
11-21 12:21:57.460: W/WindowManager(2448): No leaked surfaces; killing applicatons!
11-21 12:21:57.460: W/ActivityManager(2448): Killing processes Free memory at adjustment 5
11-21 12:21:57.460: W/ViewRootImpl(4040): No processes killed for memory; killing self
11-21 12:21:57.500: I/WindowState(2448): WIN DEATH: Window{41d5aa70 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.500: W/WindowManager(2448): Due to memory failure, waiting a bit for next layout
11-21 12:21:57.500: W/InputDispatcher(2448): channel '41da3af0 

com.example.va.datasender/com.example.va.datasender.SendData (server)' ~ Consumer closed input 

channel or an error occurred.  events=0x9
11-21 12:21:57.500: E/InputDispatcher(2448): channel '41da3af0 

com.example.va.datasender/com.example.va.datasender.SendData (server)' ~ Channel is 

unrecoverably broken and will be disposed!
11-21 12:21:57.500: I/ActivityManager(2448): Process com.example.va.datasender (pid 4040) has 

died.
11-21 12:21:57.507: W/ActivityManager(2448): Force removing ActivityRecord{41e80dd0 

com.example.va.datasender/.SendData}: app died, no saved state
11-21 12:21:57.757: W/InputDispatcher(2448): Attempted to unregister already unregistered input 

channel '41da3af0 com.example.va.datasender/com.example.va.datasender.SendData (server)'
11-21 12:21:57.757: I/WindowState(2448): WIN DEATH: Window{41da3af0 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.773: I/WindowState(2448): WIN DEATH: Window{41deb038 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.773: I/WindowState(2448): WIN DEATH: Window{41e75500 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.773: I/WindowState(2448): WIN DEATH: Window{41d296a8 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.781: I/WindowState(2448): WIN DEATH: Window{41ca39c8 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.781: I/WindowState(2448): WIN DEATH: Window{41a35a18 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.804: W/InputDispatcher(2448): channel '41caaec8 

com.example.va.datasender/com.example.va.datasender.SendData (server)' ~ Consumer closed input 

channel or an error occurred.  events=0x9
11-21 12:21:57.804: E/InputDispatcher(2448): channel '41caaec8 

com.example.va.datasender/com.example.va.datasender.SendData (server)' ~ Channel is 

unrecoverably broken and will be disposed!

...then worse errors...

11-21 12:21:57.828: I/WindowState(2448): WIN DEATH: Window{41dd0130 

com.example.va.datasender/com.example.va.datasender.SendData paused=false}
11-21 12:21:57.835: E/InputDispatcher(2448): Received spurious receive callback for unknown 

input channel.  fd=244, events=0x9
11-21 12:21:57.835: E/InputDispatcher(2448): Received spurious receive callback for unknown 

input channel.  fd=225, events=0x9
11-21 12:21:57.835: E/InputDispatcher(2448): Received spurious receive callback for unknown 

input channel.  fd=217, events=0x9
11-21 12:21:57.835: E/InputDispatcher(2448): Received spurious receive callback for unknown 

input channel.  fd=258, events=0x9
11-21 12:21:57.835: E/InputDispatcher(2448): Received spurious receive callback for unknown 

input channel.  fd=259, events=0x9
11-21 12:21:57.835: E/InputDispatcher(2448): Received spurious receive callback for unknown 

input channel.  fd=260, events=0x9

...then it crashes...

11-21 12:21:57.843: W/ActivityManager(2448): Force removing ActivityRecord{41714778 

com.example.va.datasender/.SendData}: app died, no saved state
11-21 12:21:57.843: W/ActivityManager(2448): Force removing ActivityRecord{41a69f30 

com.example.va.datasender/.SendData}: app died, no saved state
11-21 12:21:57.843: W/ActivityManager(2448): Force removing ActivityRecord{41c65b30 

com.example.va.datasender/.SendData}: app died, no saved state
11-21 12:21:57.859: D/dalvikvm(4289): Late-enabling CheckJNI
11-21 12:21:57.859: I/ActivityManager(2448): Displayed com.example.va.datasender/.SendData: 

+3s356ms (total +3s395ms)
11-21 12:21:57.859: I/ActivityManager(2448): Displayed com.example.va.datasender/.SendData: 

+3s149ms
11-21 12:21:57.859: I/ActivityManager(2448): Displayed com.example.va.datasender/.SendData: 

+1s657ms
11-21 12:21:57.859: I/ActivityManager(2448): Displayed com.example.va.datasender/.SendData: 

+2s540ms
11-21 12:21:57.859: I/ActivityManager(2448): Displayed com.example.va.datasender/.SendData: 

+977ms

...leaked surface errors...

11-21 12:21:58.343: W/WindowManager(2448): LEAKED SURFACE (app token hidden): Window{41d2df50 

com.example.va.datasender/com.example.va.datasender.SendData paused=false} surface=Surface

(name=com.example.va.datasender/com.example.va.datasender.SendData, identity=1350) 

token=AppWindowToken{41cc7c48 token=Token{4198ba08 ActivityRecord{41ca22a8 

com.example.va.datasender/.SendData}}}
11-21 12:21:58.343: W/WindowManager(2448): LEAKED SURFACE (app token hidden): Window{41d5e1b0 

com.example.va.datasender/com.example.va.datasender.SendData paused=false} surface=Surface

(name=com.example.va.datasender/com.example.va.datasender.SendData, identity=1351) 

token=AppWindowToken{41c78878 token=Token{419e78f8 ActivityRecord{41cd1208 

com.example.va.datasender/.SendData}}}

4

1 回答 1

-1

问题是你的图形内存不够。重新启动您的手机将解决此问题。

于 2013-05-09T09:22:38.787 回答