gpt4 book ai didi

java - 将 Intent 返回到另一个应用程序后出现 ResourceNotFoundException

转载 作者:行者123 更新时间:2023-12-01 22:00:38 26 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,并在其中生成一些 PDF 文件。一旦生成,我就启动一个应用程序的Intent来显示PDF(如Acrobat)。

一旦我按返回键返回到我的应用程序,它就会在采用三星修改的正常 Android 5Samsung Galaxy S5 上崩溃并出现以下错误:

11-05 17:04:29.876: E/AndroidRuntime(1515): FATAL EXCEPTION: main
11-05 17:04:29.876: E/AndroidRuntime(1515): Process: (my package), PID: 1515
11-05 17:04:29.876: E/AndroidRuntime(1515): android.content.res.Resources$NotFoundException: File res/layout-v21/adapter_historie.xml from xml type layout resource ID #0x7f04001e
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.content.res.Resources.loadXmlResourceParser(Resources.java:3953)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.content.res.Resources.loadXmlResourceParser(Resources.java:3900)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.content.res.Resources.getLayout(Resources.java:2149)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.LayoutInflater.inflate(LayoutInflater.java:413)
11-05 17:04:29.876: E/AndroidRuntime(1515): at (my package).adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:52)
11-05 17:04:29.876: E/AndroidRuntime(1515): at (my package).adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:1)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5223)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4449)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4359)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2102)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1956)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.onLayout(LinearLayout.java:1865)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2102)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1956)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.onLayout(LinearLayout.java:1865)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2102)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1956)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.LinearLayout.onLayout(LinearLayout.java:1865)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.View.layout(View.java:16550)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewGroup.layout(ViewGroup.java:5303)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2312)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2025)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1180)
11-05 17:04:29.876: E/AndroidRuntime(1515): at android.view.ViewRo

或者在带有 Cyanogenmod 12.1Google Nexus 5 上使用此堆栈跟踪:

11-06 19:47:45.871: E/AndroidRuntime(22636): FATAL EXCEPTION: main
11-06 19:47:45.871: E/AndroidRuntime(22636): Process: (my package).vaz, PID: 22636
11-06 19:47:45.871: E/AndroidRuntime(22636): android.content.res.Resources$NotFoundException: File res/layout-v21/adapter_historie.xml from xml type layout resource ID #0x7f04001e
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2843)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2798)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.content.res.Resources.getLayout(Resources.java:1143)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
11-06 19:47:45.871: E/AndroidRuntime(22636): at (my package).vaz.adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:51)
11-06 19:47:45.871: E/AndroidRuntime(22636): at (my package).vaz.adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:1)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5223)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4449)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4359)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.View.layout(View.java:15686)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
11-06 19:47:45.871: E/AndroidRuntime(22636): at android.view.ViewR

(可以找到完整的跟踪 here )

在我的代码的这一部分

public HistorienAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View layout = LayoutInflater.from(parent.getContext())
.inflate(R.layout.adapter_historie, parent, false);

return new ViewHolder(layout);
}

我在 android.app.Fragment 中启动 Intent,如下所示:

Uri path = Uri.fromFile(file);

Intent viewintent = new Intent(Intent.ACTION_VIEW);
viewintent.setDataAndType(path, "application/pdf");
getActivity().startActivity(viewintent);

最佳答案

我与 Pinguin895 一起开发了该应用程序,并在 Snild Dolkow 的精彩回答后找到了我们问题的解决方案,我们应该 try catch 异常。

我已 try catch “android.content.res.Resources.NotFoundException”并获得此堆栈跟踪,其中包含以下内容:

11-07 09:54:08.912: I/AppCompatDelegate(689): The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's
11-07 09:54:11.581: W/System.err(689): java.lang.RuntimeException: Assetmanager has been closed
11-07 09:54:11.582: W/System.err(689): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:501)
11-07 09:54:11.582: W/System.err(689): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2825)
11-07 09:54:11.582: W/System.err(689): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2798)
11-07 09:54:11.582: W/System.err(689): at android.content.res.Resources.getLayout(Resources.java:1143)
11-07 09:54:11.582: W/System.err(689): at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
11-07 09:54:11.582: W/System.err(689): at (my package).vaz.adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:53)
11-07 09:54:11.582: W/System.err(689): at (my package).vaz.adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:1)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5223)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4449)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4359)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
11-07 09:54:11.582: W/System.err(689): at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
11-07 09:54:11.582: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.582: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.582: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.582: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.582: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.582: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.582: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.582: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.582: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.582: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.583: W/System.err(689): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
11-07 09:54:11.583: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.583: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-07 09:54:11.583: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.583: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.583: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.583: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.583: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.583: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-07 09:54:11.583: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.583: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.583: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.583: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.583: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.583: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-07 09:54:11.583: W/System.err(689): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-07 09:54:11.584: W/System.err(689): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-07 09:54:11.584: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.584: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.584: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.584: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.584: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.584: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.584: W/System.err(689): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
11-07 09:54:11.584: W/System.err(689): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
11-07 09:54:11.584: W/System.err(689): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
11-07 09:54:11.584: W/System.err(689): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5891)
11-07 09:54:11.584: W/System.err(689): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
11-07 09:54:11.584: W/System.err(689): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
11-07 09:54:11.584: W/System.err(689): at android.view.Choreographer.doFrame(Choreographer.java:550)
11-07 09:54:11.584: W/System.err(689): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
11-07 09:54:11.584: W/System.err(689): at android.os.Handler.handleCallback(Handler.java:739)
11-07 09:54:11.584: W/System.err(689): at android.os.Handler.dispatchMessage(Handler.java:95)
11-07 09:54:11.584: W/System.err(689): at android.os.Looper.loop(Looper.java:135)
11-07 09:54:11.584: W/System.err(689): at android.app.ActivityThread.main(ActivityThread.java:5294)
11-07 09:54:11.584: W/System.err(689): at java.lang.reflect.Method.invoke(Native Method)
11-07 09:54:11.584: W/System.err(689): at java.lang.reflect.Method.invoke(Method.java:372)
11-07 09:54:11.584: W/System.err(689): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
11-07 09:54:11.584: W/System.err(689): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
11-07 09:54:11.584: W/System.err(689): android.content.res.Resources$NotFoundException: File res/layout-v21/adapter_historie.xml from xml type layout resource ID #0x7f04001e
11-07 09:54:11.585: W/System.err(689): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2843)
11-07 09:54:11.585: W/System.err(689): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2798)
11-07 09:54:11.585: W/System.err(689): at android.content.res.Resources.getLayout(Resources.java:1143)
11-07 09:54:11.585: W/System.err(689): at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
11-07 09:54:11.585: W/System.err(689): at (my package).vaz.adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:53)
11-07 09:54:11.585: W/System.err(689): at (my package).vaz.adapter.HistorienAdapter.onCreateViewHolder(HistorienAdapter.java:1)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5223)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4449)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4359)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
11-07 09:54:11.585: W/System.err(689): at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
11-07 09:54:11.585: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.585: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.585: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.585: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.585: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.585: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.585: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.586: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.586: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.586: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
11-07 09:54:11.586: W/System.err(689): at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
11-07 09:54:11.586: W/System.err(689): at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
11-07 09:54:11.586: W/System.err(689): at android.view.View.layout(View.java:15686)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewGroup.layout(ViewGroup.java:5039)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
11-07 09:54:11.586: W/System.err(689): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
11-07 09:54:11.587: W/System.err(689): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
11-07 09:54:11.587: W/System.err(689): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5891)
11-07 09:54:11.587: W/System.err(689): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
11-07 09:54:11.587: W/System.err(689): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
11-07 09:54:11.587: W/System.err(689): at android.view.Choreographer.doFrame(Choreographer.java:550)
11-07 09:54:11.587: W/System.err(689): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
11-07 09:54:11.587: W/System.err(689): at android.os.Handler.handleCallback(Handler.java:739)
11-07 09:54:11.587: W/System.err(689): at android.os.Handler.dispatchMessage(Handler.java:95)
11-07 09:54:11.587: W/System.err(689): at android.os.Looper.loop(Looper.java:135)
11-07 09:54:11.587: W/System.err(689): at android.app.ActivityThread.main(ActivityThread.java:5294)
11-07 09:54:11.587: W/System.err(689): at java.lang.reflect.Method.invoke(Native Method)
11-07 09:54:11.587: W/System.err(689): at java.lang.reflect.Method.invoke(Method.java:372)
11-07 09:54:11.587: W/System.err(689): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
11-07 09:54:11.587: W/System.err(689): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
11-07 09:54:11.587: W/System.err(689): Caused by: java.lang.RuntimeException: Assetmanager has been closed
11-07 09:54:11.587: W/System.err(689): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:501)
11-07 09:54:11.587: W/System.err(689): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2825)
11-07 09:54:11.587: W/System.err(689): ... 70 more

经过一些研究,Assetmanager 已被关闭。我发现 assetmanager 不应该关闭,因为 android 应用程序需要它来访问 .apk 中包含的文件(如布局 xml 文件)

在我们的应用程序中,我们使用 assetmanager 选择一个 pdf 文件,该文件位于 apk 内的 asset 文件夹中。输入一些文本后,更改后的 pdf 会保存在 SD 卡上。

try (AssetManager am = context.getAssets();
InputStream is = am.open(vaz.getDatei() + ".pdf");
OutputStream targetOutputStream = new FileOutputStream(file)) {

/*
*[SOME CODE FOR GENERATION AND SAVING]
*/

Uri path = Uri.fromFile(file);

Intent viewintent = new Intent(Intent.ACTION_VIEW);
viewintent.setDataAndType(path, "application/pdf");
getActivity().startActivity(viewintent);

} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}

我们对 java.lang.AutoCloseable 使用了 try-with-resources从 PDF-Viewer-App 返回后,assetmanger 已关闭,因为 java.lang.AutoCloseable

修复方法是将 assetmanger 置于 try-with-resources 之外:

AssetManager am = context.getAssets();

try (InputStream is = am.open(vaz.getDatei() + ".pdf");
OutputStream targetOutputStream = new FileOutputStream(file)) {

...

} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}

感谢您的努力 Snild Dolkow!

关于java - 将 Intent 返回到另一个应用程序后出现 ResourceNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33549840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com