Java tutorial
//package com.java2s; import java.io.Closeable; import android.database.Cursor; public class Main { public static void closeSafely(Closeable closeable) { try { if (closeable != null) { closeable.close(); } } catch (Exception e) { e.printStackTrace(); } } public static void closeSafely(Cursor cursor) { try { if (cursor != null && !cursor.isClosed()) { cursor.close(); } } catch (Exception e) { e.printStackTrace(); } } }