为什么使用Java的反射机制调用setDataSource方法,就可以在Java层捕获Native层的异常了
时间: 2024-05-24 19:11:39 浏览: 11
使用Java的反射机制调用setDataSource方法可以在Java层捕获Native层的异常,是因为反射机制可以动态地获取一个类的方法和属性,并且可以在运行时动态地调用这些方法和属性。在调用setDataSource方法时,如果Native层抛出异常,Java层的反射机制会将这个异常捕获,并且以Java异常的形式抛出给调用者,从而实现了在Java层捕获Native层异常的功能。
相关问题
System.err: at android.media.MediaMetadataRetriever.setDataSource(Native Method)这是native层捕获的异常吗,应用层代码可以捕获吗
是的,这是native层抛出的异常。应用层代码可以捕获这个异常,但需要使用try-catch语句块来捕获,并处理该异常。例如:
try {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(filePath);
} catch (IllegalArgumentException e) {
// 处理异常
}
System.err: at android.media.MediaMetadataRetriever.setDataSource(Native Method)这是native层捕获的异常吗
是的,这是native层捕获的异常。在这个错误消息中,"at android.media.MediaMetadataRetriever.setDataSource(Native Method)"表示该异常发生在MediaMetadataRetriever类的setDataSource方法的本地代码中,也就是native层。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)