[英]How to solve the error for File object's parameter in Android Studio IDE
我正在嘗試獲取文件列表和我的代碼,如下所示。
public static void deleteWithExtension(Context mContext, String extension) {
File dir = new File(mContext.getFilesDir());
final String[] theFiles = dir.list();
for (final String file : theFiles) {
//do something here....
int aa=9;
//The code never goes into here, because theFiles Array is always null
}
}
}
但是 IDE 在第 2 行顯示紅色下划線 -> File dir = new File( mContext.getFilesDir() );
它在該行的部分 -> mContext.getFilesDir() 下划線。
當我將鼠標移到那個紅色下划線部分時,我得到一個解釋說“無法解析構造函數'File(java.io.File)'”
只是通知一下,導入java.io.File; 存在於我的代碼的頂部。
為什么會這樣以及如何解決。 先感謝您...
getFilesDir()
已經返回了一個File
object,因此您可以完全刪除new File
部分並直接使用返回的File
:
File dir = mContext.getFilesDir();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.