Buggy code:
public static final int TASK_TYPE_REDO = 9 ; public static final int TASK_TYPE_LOAD_CARDS = 10 ; public static final int TASK_TYPE_BURY_CARD = 11 ; public static final int TASK_TYPE_DELETE_CARD = 12 ; public static final int TASK_TYPE_LOAD_STATISTICS = 13 ; public static final int TASK_TYPE_OPTIMIZE_DECK = 14 ; public static final int TASK_TYPE_SET_ALL_DECKS_JOURNAL_MODE = 15 ; public static final int TASK_TYPE_CLOSE_DECK = 16 ; public static final int TASK_TYPE_DELETE_BACKUPS = 17 ; public static final int TASK_TYPE_RESTORE_DECK = 18 ; public static final int TASK_TYPE_SORT_CARDS = 19 ; public static final int TASK_TYPE_LOAD_TUTORIAL = 20 ; public static final int DECK_LOADED = 0 ; public static final int DECK_NOT_LOADED = 1 ; public static final int DECK_EMPTY = 2 ; public static final int TUTORIAL_NOT_CREATED = 3 ; private static DeckTask sInstance ; private static DeckTask sOldInstance ; private int mType ; private DeckTask . TaskListener mListener ; public static DeckTask launchDeckTask ( int type , DeckTask . TaskListener listener , DeckTask . TaskData ... params ) { } public static void waitToFinish ( ) { } public static boolean taskIsRunning ( ) { } @ Override protected DeckTask . TaskData doInBackground ( DeckTask . TaskData ... params ) { } @ Override protected void onPreExecute ( ) { } @ Override protected void onProgressUpdate ( DeckTask . TaskData ... values ) { } @ Override protected void onPostExecute ( DeckTask . TaskData result ) { } private DeckTask . TaskData doInBackgroundAddFact ( DeckTask . TaskData [ ] params ) { } private DeckTask . TaskData doInBackgroundUpdateFact ( DeckTask . TaskData [ ] params ) { } private DeckTask . TaskData doInBackgroundAnswerCard ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundLoadDeck ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundSaveDeck ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundSuspendCard ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundMarkCard ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundUndo ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundRedo ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundLoadCards ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundDeleteCard ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundBuryCard ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundLoadStatistics ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundOptimizeDeck ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundSetJournalMode ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundCloseDeck ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundDeleteBackups ( ) { } private DeckTask . TaskData doInBackgroundRestoreDeck ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundSortCards ( DeckTask . TaskData ... params ) { } private DeckTask . TaskData doInBackgroundLoadTutorial ( DeckTask . TaskData ... params ) { Log . i ( TAG , "doInBackgroundLoadTutorial" ) ; Resources res = AnkiDroidApp . getInstance ( ) . getBaseContext ( ) . getResources ( ) ; File sampleDeckFile = new File ( params [ 0 ] . getString ( ) ) ; publishProgress ( new DeckTask . TaskData ( res . getString ( tutorial_load ) ) ) ; AnkiDb ankiDB = null ; try { InputStream stream = res . getAssets ( ) . open ( EMPTY_DECK_NAME ) ; Utils . writeToFile ( stream , sampleDeckFile . getAbsolutePath ( ) ) ; stream . close ( ) ; Deck . initializeEmptyDeck ( sampleDeckFile . getAbsolutePath ( ) ) ; String [ ] questions = res . getStringArray ( tutorial_questions ) ; String [ ] answers = res . getStringArray ( tutorial_answers ) ; String [ ] sampleQuestions = res . getStringArray ( tutorial_capitals_questions ) ; String [ ] sampleAnswers = res . getStringArray ( tutorial_capitals_answers ) ; <START_BUG> Deck deck = Deck . openDeck ( sampleDeckFile . getAbsolutePath ( ) , false ) ; <END_BUG> ankiDB = AnkiDatabaseManager . getDatabase ( deck . getDeckPath ( ) ) ; ankiDB . getDatabase ( ) . beginTransaction ( ) ; try { CardModel cardModel = null ; int len = Math . min ( questions . length , answers . length ) ; for ( int i = 0 ; i < ( len + ( Math . min ( sampleQuestions . length , sampleAnswers . length ) ) ) ; i ++ ) { Fact fact = deck . newFact ( ) ; if ( cardModel == null ) { cardModel = deck . activeCardModels ( fact ) . entrySet ( ) . iterator ( ) . next ( ) . getValue ( ) ; } int fidx = 0 ; for ( Fact . Field f : fact . getFields ( ) ) { if ( fidx == 0 ) { f . setValue ( ( i < len ? questions [ i ] : sampleQuestions [ ( i - len ) ] ) ) ; } else if ( fidx == 1 ) { f . setValue ( ( i < len ? answers [ i ] : sampleAnswers [ ( i - len ) ] ) ) ; } fidx ++ ; } if ( ! ( deck . importFact ( fact , cardModel ) ) ) { sampleDeckFile . delete ( ) ; return new DeckTask . TaskData ( DeckTask . TUTORIAL_NOT_CREATED ) ; } } deck . setSessionTimeLimit ( 0 ) ; deck . flushMod ( ) ; deck . reset ( ) ; AnkiDroidApp . setDeck ( deck ) ; ankiDB . getDatabase ( ) . setTransactionSuccessful ( ) ; return new DeckTask . TaskData ( DeckTask . DECK_LOADED , deck , null ) ; } finally { ankiDB . getDatabase ( ) . endTransaction ( ) ; } }

Fix:
Deck deck = Deck . openDeck ( sampleDeckFile . getAbsolutePath ( ) ) ;