嗨,我有一个小问题
我有此代码可将图像保存到SD卡中
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");
并且即时消息显示2个错误,第一个是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)
有关如何修复它的一些帮助。....
谢谢
public String
,这意味着如果您不希望函数返回任何内容,则必须从函数中返回String对象(使用return
关键字),请使用void
关键字代替String
。第二个错误意味着您在某个地方使用字符串作为参数(SDSave
)调用了SDSave(extStorageDirectory + "/qr11.PNG");
方法,而此函数不接受任何参数(public String SDSave( )
)。
[我建议您尝试Java tutorial或two,因为这些规则是Java(实际上是许多编程语言)的基础。
public String SDSave()
您需要在代码末尾的行:
return "someString";
如果您不想返回字符串,请使用:
public void SDSave()
第二个错误,您试图将String传递到您的方法中,但是您的方法没有任何变量。您将需要:
public void SDSave(String myInputStringVariable)
是的,这些是Java basic的,所以我将继续阅读Java和OO,也请查看以下内容:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
希望对您有帮助。
public void SDSave(String file){
File f=new File(file);
...
}