简体   繁体   English

在Android中获取Java.io.closeable错误

[英]Getting Java.io.closeable Error in Android

I am getting the following error. 我收到以下错误。 While running my program. 在运行我的程序时。 I am unable to understand the problem. 我无法理解问题。 A resource was acquired at attached stack trace but never released. 在附加的堆栈跟踪中获取了资源,但从未释放过。 See java.io.Closeable for information on avoiding resource leaks. 有关避免资源泄漏的信息,请参见java.io.Closeable。

Code

ArrayList<String> selection = new ArrayList<>();
TextView finaltext = null;
    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
        finaltext = (TextView)findViewById(R.id.final_result);
        finaltext.setEnabled(false);
}
public void selectItem(View view)
{
    boolean checked = ((CheckBox) view).isChecked();
    switch (view.getId())
    {
        case R.id.fruit_apple:if (checked){selection.add("Apple");}else {selection.remove("Apple");}
        break;
        case R.id.fruit_orange:if (checked){selection.add("Orange");}else {selection.remove("Orange");}
        break;
        case R.id.fruit_grape:if (checked){selection.add("Grapes");}else {selection.remove("Grapes");}
        break;
    }
}

XML XML格式

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/title_message"
    android:textAppearance="?android:textAppearanceLarge"
    android:layout_gravity="center_horizontal"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fruit_apple"
android:text="@string/apple"
android:onClick="selectItem"/>
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/fruit_orange"
    android:text="@string/orange"
    android:onClick="selectItem"
    />
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/fruit_grape"
    android:text="@string/grapes"
    android:onClick="selectItem"/>
<Button
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:text="done"
    android:layout_gravity="center_horizontal"
    android:onClick="finalSelection"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/final_result"
    android:text="Hello World"/>
</RelativeLayout>

That means you have opened something but never close them. 这意味着您已经打开了某些东西,但从未关闭它们。 Closable have a method close which you must call to release the resources associated with the component when you no longer need it. Closable具有close方法,当您不再需要该方法时,必须调用该方法以释放与该组件关联的资源。

To look for the leak, you can try MAT , I often use it to find memory leaks(static data holding a reference to Activity, etc). 要查找泄漏,您可以尝试MAT ,我经常用它来查找内存泄漏(持有对Activity的引用的静态数据等)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.Closeable:为什么在 close() 中抛出 RuntimeException 有效? - java.io.Closeable: why throwing RuntimeException in close() works? Android:在附加的堆栈跟踪中获取资源但从未发布。 有关避免资源泄漏的信息,请参阅java.io.Closeable - Android: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks com.mysql.jdbc.JDBC4ResultSet无法转换为java.io.Closeable - com.mysql.jdbc.JDBC4ResultSet cannot be cast to java.io.Closeable 为什么java.lang.AutoCloseable的close方法会抛出异常,但java.io.Closeable的close方法会抛出IOException? - Why close method of java.lang.AutoCloseable throws Exception, but close method of java.io.Closeable throws IOException? 在附加的堆栈跟踪中获取了资源但从未释放过。 有关避免资源泄漏的信息,请参阅 java.io.Closeable,为什么会发生这种情况 - A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks, why this happens java.lang.NoSuchMethodError:com.google.common.io.Closeables.closeQuietly(Ljava / io / Closeable;)V - java.lang.NoSuchMethodError: com.google.common.io.Closeables.closeQuietly(Ljava/io/Closeable;)V com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: java.io.StringReader, which is a closeable resource - com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: java.io.StringReader, which is a closeable resource 获取java.io.NotSerializableException错误 - Getting java.io.NotSerializableException error 如何在Java中组合Closeable对象? - How to compose Closeable objects in Java? Java扫描程序是否实现Closeable? - Does Java scanner implement Closeable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM