![](/img/trans.png)
[英]java.io.Closeable: why throwing RuntimeException in close() works?
[英]Getting Java.io.closeable Error in Android
我收到以下错误。 在运行我的程序时。 我无法理解问题。 在附加的堆栈跟踪中获取了资源,但从未释放过。 有关避免资源泄漏的信息,请参见java.io.Closeable。
码
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格式
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.