首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Constants.java的未定义构造函数

Constants.java的未定义构造函数
EN

Stack Overflow用户
提问于 2015-02-21 07:43:09
回答 2查看 99关注 0票数 0

在Asynctask中的片段类中,我得到了一个构造函数未定义的错误。

代码语言:javascript
复制
protected String doInBackground(String... f_url) {
 ..............
 .............
File file = new File(Constants.getAudioStoragePath()); --->Undefined constructor


//this will be used to write the downloaded data into the file we created

FileOutputStream fileOutput = new FileOutputStream(file);

}

Constants.java:

代码语言:javascript
复制
public static File getAudioStoragePath(Context context, String folderName) throws IOException {
    File baseFolder =  getFolder(context, "audio");
    File folder = new File(baseFolder, folderName);
    if (!folder.exists())  folder.mkdirs();
    return folder;
}

任何人都可以帮我处理这个参数,我必须传递给it.Thank你。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-21 07:53:30

添加到answer of Johan Prins中,传递适当的参数,如:

File file = Constants.getAudioStoragePath(getActivity(), "myFolder");

票数 1
EN

Stack Overflow用户

发布于 2015-02-21 07:48:58

文件不包含接受File对象的构造函数。

将一行代码替换为:

代码语言:javascript
复制
File file = Constants.getAudioStoragePath();

请注意,还需要更新常量类,以包含不接受参数的getAudioStoragePath()方法。

以上将修复您的“未定义构造函数”错误。下一个问题很可能是当您创建一个FileOutputStream时。如果我正确阅读这段代码,您从常量中获得的文件实际上是一个目录。您需要在您写入的目录中创建一个文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28643432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档