我有一個小問題,我用下面的代碼在SD card中保存圖片:
public String SDSave( ) { //View arg0
// TODO Auto-generated method stub
OutputStream outStream = null;
File file = new File( extStorageDirectory , AdName + ".PNG");
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Toast.makeText(WhereAmI.this, "Saved", Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(WhereAmI.this, e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(WhereAmI.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
我用以下方法調用它:
String sdSave = SDSave(extStorageDirectory + "/qr11.PNG");
然後顯示倆個錯誤,第一個是在public String SDSave( )
,
錯誤 This method must return a result of type String
第二個是String sdSave = SDSave(extStorageDirectory + "/qr11.PNG");
,
錯誤 The method SDSave() in the type WhereAmI is not applicable for the arguments (String)
請求大牛幫忙改正,好困惑。謝謝!
在manifest文件中寫入:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
就不用那麼麻煩了。