什么是空指针异常(java.lang.NullPointerException
)以及它们的原因是什么?
可以使用哪些方法/工具来确定原因,以便停止异常导致程序过早终止?
public class Utils {
public static List<Message> getMessages() {
//File file = new File("file:///android_asset/helloworld.txt");
AssetManager assetManager = getAssets();
InputStream ims = assetManager.open("helloworld.txt");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码尝试从资产中读取文件.我尝试了两种方法来做到这一点.首先,当File
我收到使用FileNotFoundException
时,使用AssetManager getAssets()
方法时无法识别.这里有解决方案吗?