我最近写了一个非常小的程序,把一个指定数组生成幅图片并保存在sd卡上,但不知道是什么原因在执行压缩那句话时,程序抛出了,而且sd卡上也没有相应的文件夹生成。哪位大神能告诉我是怎么回事。
public class SaveActivity extends Activity { /** Called when the activity is first created. */ public Button btn; public ImageView img; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img=(ImageView)findViewById(R.id.img); btn=(Button)findViewById(R.id.btn); onclick(); } public void onclick(){ btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveImage(); } private void saveImage() { // TODO Auto-generated method stub int [] a= new int [16384]; for(int i =0;i<16384;i++) a[i] = -1601933; Bitmap bmp = Bitmap.createBitmap(a, 0,128, 128, 128,Bitmap.Config.RGB_565); img.setImageBitmap(bmp); File filename; try { String path = Environment.getExternalStorageDirectory().toString(); new File(path + "/folder/subfolder").mkdirs(); filename = new File(path + "/folder/subfolder/image.jpg"); FileOutputStream out = new FileOutputStream(filename); [color=#FF0000]boolean m = bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);[/color] out.flush(); out.close(); MediaStore.Images.Media.insertImage(getContentResolver(), filename.getAbsolutePath(), filename.getName(), filename.getName()); Toast.makeText(getApplicationContext(), "File is Saved in " + filename, 1000).show(); } catch (Exception e) { e.printStackTrace(); System.out.println("s;dlfkjg"); } } }); }
另外权限<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>已经加上了,不是权限的问题
怎么不把抛出的异常贴出来呢?那个才是分析问题的入口呀。
ok 了
抱什么异常 那句话异常?