SqliteOpenHelper in TabbedFragment getting stackOverFlow error and TransactionTooLargeException

229 views Asked by At

I'm trying to use a database (extended from SqliteOpenHelper) in a TabbedFragment in Android. But I'm having a StackOverFlow error and a TransactionTooLarge Exception, here is my logcat:

`--------- beginning of crash
com.wen.databaseinfragment E/AndroidRuntime: FATAL EXCEPTION: main
     Process: com.wen.databaseinfragment, PID: 6566
     java.lang.StackOverflowError: stack size 8MB
     at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5901)
     at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java
 com.wen.databaseinfragment D/Error: ERR: exClass=java.lang.StackOverflowError
 com.wen.databaseinfragment D/Error: ERR: exMsg=stack size 8MB
 com.wen.databaseinfragment D/Error: ERR: file=ViewGroup.java
 com.wen.databaseinfragment D/Error: ERR: class=android.view.ViewGroup
 com.wen.databaseinfragment D/Error: ERR: method=jumpDrawablesToCurrentState line=5901
 D/Error: ERR: stack=java.lang.StackOverflowError: stack size 8MB
          at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5901)
          at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
          at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewG
 D/Error: ERR: TOTAL BYTES WRITTEN: 13245704
 E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
 E/AndroidRuntime: Error reporting crash
               android.os.TransactionTooLargeException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:496)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4164)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:89)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)'

` This is my Fragment Class:

public class dataBaseFragment extends Fragment {
    private static final String TAG = "DataBaseFragment";
    private TextView tv;
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v= inflater.inflate(R.layout.data_base_fragment,container,true);
        Database db= new Database(getActivity().getApplicationContext());
        SQLiteDatabase dbWrite= db.getWritableDatabase();
        tv= (TextView) v.findViewById(R.id.tv);
        tv.setText("Ciaoooooooo");
        Log.d(TAG, "onCreateView: ");
        ContentValues cv= new ContentValues();
        cv.put("name","pippo");
        cv.put("sex","maschio");
        dbWrite.insert("user",null,cv);
        cv= new ContentValues();
        cv.put("name","tizia");
        cv.put("sex","femmina");
        dbWrite.insert("user",null,cv);
        db.close();
        SQLiteDatabase dbRead = db.getReadableDatabase();
        Cursor cursor= dbRead.query("user",new String[]{"name","sex"},"name=?",new String[]{"pippo"},null,null,null);
        while(cursor.moveToNext())
        {
           String name= cursor.getString(cursor.getColumnIndex("name"));
            String sex =cursor.getString(cursor.getColumnIndex("sex"));
            Log.d(TAG,String.format("name=%s, sex=%s",name,sex ));
        }
        return v;
    }
}

and this is my Sqlite Openhelper Class:

public class Database extends SQLiteOpenHelper {

    public Database(Context context) {
        super(context, "db", null,1);
    }

    public void onCreate(SQLiteDatabase db) {

        db.execSQL("CREATE TABLE user(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "name TEXT DEFAULT \"\"," +
                "sex TEXT DEFAULT \"\")");
    }
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {    
    }
}
1

There are 1 answers

4
bwt On

What happen if you don't attach the inflated view :

View v= inflater.inflate(R.layout.data_base_fragment,container,false);

You should not attach the fragment's view to the container yourself, although it is probably not the only problem (the exception thrown would be an IllegalStateException)