我正在尝试整合一个简单的应用程序,该应用程序可以获取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()
{
}
}
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()
{
}
}
答案 0 :(得分:-1)
问题是你的图形内存还不够。重新启动手机将解决此问题。