java.lang.RuntimeException: 无法从 Parcel 读取输入通道文件描述符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25132509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.RuntimeException: Could not read input channel file descriptors from parcel
提问by chancyWu
I am using crashlytics to track my app's crash. There is one bug which is quite hard to figure out. The stack trace from crashlytics is as below:
我正在使用 crashlytics 来跟踪我的应用程序的崩溃情况。有一个很难弄清楚的错误。来自 crashlytics 的堆栈跟踪如下:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
at android.view.InputChannel.nativeReadFromParcel(InputChannel.java)
at android.view.InputChannel.readFromParcel(InputChannel.java:148)
at android.view.InputChannel.createFromParcel(InputChannel.java:39)
at android.view.InputChannel.createFromParcel(InputChannel.java:36)
at com.android.internal.view.InputBindResult.<init>(InputBindResult.java:62)
at com.android.internal.view.InputBindResult.createFromParcel(InputBindResult.java:102)
at com.android.internal.view.InputBindResult.createFromParcel(InputBindResult.java:99)
at com.android.internal.view.IInputMethodManager$Stub$Proxy.windowGainedFocus(IInputMethodManager.java:851)
at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1292)
at android.view.inputmethod.InputMethodManager.onWindowFocus(InputMethodManager.java:1518)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3550)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
I know there is one similar question about this here. But there is a bit different. And as statistics from crashlytics, the crash happens mainly in SAMSUNG android phone.
我知道有这一个类似的问题在这里。但有一点不同。根据 crashlytics 的统计,崩溃主要发生在 SAMSUNG android 手机中。
I am new to android and don't know why the crash happened and how to fix this kind of crash.
我是 android 新手,不知道为什么会发生崩溃以及如何修复这种崩溃。
Any suggestion would be much appreciated.
任何建议将不胜感激。
采纳答案by Andrew Terekhine
Think it's a very wide area and there could be a lot of situations which can trigger this system level exception. But maybe this example of how it was fixed in a particular project can help someone.
认为这是一个非常广泛的领域,可能有很多情况会触发此系统级异常。但也许这个在特定项目中如何修复它的例子可以帮助某人。
I experienced a similar exception:"Could not read input channel file descriptors from parcel"
on Samsung phone:
我遇到了类似的异常:"Could not read input channel file descriptors from parcel"
在三星手机上:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
at android.view.InputChannel.nativeReadFromParcel(Native Method)
at android.view.InputChannel.readFromParcel(InputChannel.java:148)
at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:690)
at android.view.ViewRootImpl.setView(ViewRootImpl.java:525)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:269)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.widget.Toast$TN.handleShow(Toast.java:402)
at android.widget.Toast$TN.run(Toast.java:310)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
It happened in a big old project which I got for maintenance and this floating bug occurred only after several hours. I spent quite some time on it and also read some related answers on SO regarding it and had no clue except it's a system level bug of Android, and there should be some extra data or duplicates of objects or big objects in memory etc:
它发生在我进行维护的一个大型旧项目中,这个浮动错误仅在几个小时后发生。我花了相当多的时间,还阅读了一些关于它的相关答案,除了它是 Android 的系统级错误之外一无所知,并且应该有一些额外的数据或对象或内存中的大对象的副本等:
https://code.google.com/p/android/issues/detail?id=32470
https://code.google.com/p/android/issues/detail?id=32470
The last thing I could think about was SoundPool. It's not used a lot in the project - there are not more than 10 different sounds played from time to time.
But it was the root cause! Sometimes there were floating exceptions from SoundPool "unable to load sample (null)"
. And it helped to realize that SoundPool was used in a wrong way:
我能想到的最后一件事是 SoundPool。它在项目中使用得并不多 - 不时播放的不同声音不超过 10 种。
但这是根本原因!有时会有来自 SoundPool 的浮动异常"unable to load sample (null)"
。它有助于意识到 SoundPool 的使用方式是错误的:
public void play(int rscId) {
...
final int soundId = soundPool.load(mContext, rscId, 1);
...
soundPool.play(soundId, volume, volume, 5, 0, 1f);
So new id was generated and sound resource was reloaded each time application called play sound method! And after certain amount of time some non related exceptions started to occur until application crashed with the "Could not read input channel file descriptors from parcel"
exception.
It's interesting that one of those non related exceptions was:"ExceptionHandled in unable to open database file (code 14)"
:
因此,每次应用程序调用播放声音方法时,都会生成新的 id 并重新加载声音资源!一段时间后,一些不相关的异常开始发生,直到应用程序因"Could not read input channel file descriptors from parcel"
异常而崩溃。
有趣的是,这些不相关的例外之一是"ExceptionHandled in unable to open database file (code 14)"
:
ExceptionHandled in unable to open database file (code 14)
android.database.sqlite.SQLiteCantOpenDatabaseException:
unable to open database file (code 14)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow
(Native Method)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow
(SQLiteConnection.java:845)
And of course it has nothing to do neither with database nor with toasts/parcels. The fix for that particular situation was very easy: just preload all sounds as it's suggested in Android documentation:
当然,它与数据库无关,也与 toasts/parcels 无关。这种特殊情况的修复非常简单:只需按照 Android 文档中的建议预加载所有声音:
http://developer.android.com/reference/android/media/SoundPool.html
http://developer.android.com/reference/android/media/SoundPool.html
"The loading logic iterates through the list of sounds calling the appropriate SoundPool.load() function
. This should typically be done early in the process to allow time for decompressing the audio to raw PCM format before they are needed for playback.
Once the sounds are loaded and play has started, the application can trigger sounds by calling SoundPool.play()
."
“加载逻辑通过声音调用适当的列表上循环SoundPool.load() function
,这通常应该在早期进行,以便有时间需要回放才解压缩音频原始PCM格式。
一旦声音加载和播放已开始,应用程序可以通过调用来触发声音SoundPool.play()
。”
So I moved soundPool.load() out from play() method
and the exception :"Could not read input channel file descriptors from parcel"
has gone as well as the exception "unable to open database file (code 14)"
.
所以我感动soundPool.load() out from play() method
了,异常:和异常一样"Could not read input channel file descriptors from parcel"
消失了"unable to open database file (code 14)"
。
public void play(int soundId) {
...
soundPool.play(soundId, volume, volume, 5, 0, 1f);
And soundPool.release(); soundPool = null
should be called as well when it's not needed anymore. And maybe it also can have an effect on such exceptions, see details here
并且soundPool.release(); soundPool = null
在不再需要时也应该调用它。也许它也可以对此类异常产生影响,请参阅此处的详细信息
Could not read input channel file descriptors from parcel
Most probably it's not the exact situation for the original question but hope it can give some information to dig further. I.e. looking for some additional exceptions, swallowed exceptions, or wrong files/data handling.
很可能这不是原始问题的确切情况,但希望它可以提供一些信息以进一步挖掘。即寻找一些额外的异常、吞下的异常或错误的文件/数据处理。
回答by Yrom
I am looking for the answer for a long time such as the others facing at this exception.
我正在寻找答案很长一段时间,例如在此异常中面临的其他人。
As I see it, this crash can also be triggered by the unexceptional TextView
or EditText
which works with the InputMethodManager
:
在我看来,这种崩溃也可以由非异常触发TextView
或EditText
与以下情况一起使用InputMethodManager
:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
at android.view.InputChannel.nativeReadFromParcel(Native Method)
at android.view.InputChannel.readFromParcel(InputChannel.java:148)
at android.view.InputChannel.createFromParcel(InputChannel.java:39)
at android.view.InputChannel.createFromParcel(InputChannel.java:36)
at com.android.internal.view.InputBindResult.<init>(InputBindResult.java:68)
at com.android.internal.view.InputBindResult.createFromParcel(InputBindResult.java:112)
at com.android.internal.view.InputBindResult.createFromParcel(InputBindResult.java:109)
at com.android.internal.view.IInputMethodManager$Stub$Proxy.startInput(IInputMethodManager.java:697)
at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1407)
at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1518)
at android.view.inputmethod.InputMethodManager.restartInput(InputMethodManager.java:1286)
at android.widget.TextView.setText(TextView.java:4718)
at android.widget.TextView.setText(TextView.java:4656)
at android.widget.TextView.append(TextView.java:4330)
at android.widget.TextView.append(TextView.java:4320)
...
When TextView
appending text, it will make text to Editable
, and start InputMethodManager
. But at this time, something goes wrong in the InputMethod
process, and it leads to fail to create InputBindResult
which reading error from the parcel.
当TextView
追加文本,它会使文本Editable
,并开始InputMethodManager
。但此时,InputMethod
过程中出了点问题,导致无法InputBindResult
从包裹中创建哪个读取错误。
In this case, the workaround is very simple: DO NOT call append on textview directly, use StringBuilder
or SpannableStringBuilder
to build text and call TextView.setText(text)
instead!
在这种情况下,解决方法非常简单:不要直接在 textview 上调用 append,而是使用StringBuilder
或SpannableStringBuilder
构建文本并调用TextView.setText(text)
!
回答by SmrtGrunt quit because Monica
Previous users have commented that this can be a hard bug to track down. I caused this by building a custom alert dialog (containing multiple TextView
objects) inside of a while
loop vice an if
statement. The application crashed before displaying the dialog box(es).
以前的用户评论说,这可能是一个很难追踪的错误。我通过TextView
在while
循环内构建自定义警报对话框(包含多个对象)来导致此问题,而不是if
语句。应用程序在显示对话框之前崩溃。
回答by cegprakash
I got this error because of running too many queries on Activity launch (for each row in a list view). Because I tried to reopen the same activity while the queries were being executed.
我收到此错误是因为在 Activity 启动时运行了太多查询(对于列表视图中的每一行)。因为我试图在执行查询时重新打开相同的活动。
Fix : I ran only one query for the listview.
修复:我只对列表视图运行了一个查询。
回答by stone Lenord
I have meet this problem recently.
我最近遇到了这个问题。
java.lang.RuntimeException: Could not read input channel file descr
iptors from parcel.
I search the log find following info:
我搜索日志找到以下信息:
01-01 09:07:52.164 5162 6777 W zygote64: ashmem_create_region failed for 'indirect ref table': Too many open files
01-01 09:07:52.164 5162 6777 W zygote64:ashmem_create_region 因“间接引用表”失败:打开的文件太多
The problem is that I create HandlerThread repeatedly, but don't do it's quit() method, at last result in fd leaked.
问题是我反复创建了HandlerThread,但是不做quit()方法,最后导致fd泄露。