0

我想开始从onPostExecute()方法的活动在此上课的时候崩溃:开展活动

private class LoadFragmentTask extends AsyncTask<Void, Void, Void> { 


    private View view; 
    private Bundle bundle; 

    public LoadFragmentTask(View view){ 
     this.view = view; 
    } 

    @Override 
    protected void onPreExecute(){ 
     progressDialog = new ProgressDialog(getContext()); 
     progressDialog.setMessage("Loading..."); 
     progressDialog.setIndeterminate(true); 
     progressDialog.setCancelable(false); 
     progressDialog.show(); 
    } 

    @Override 
    protected Void doInBackground(Void... voids) { 
     Dictionary dictionary = new com.example.james.ultimatescrabbleapp.Dictionary(); 
     final DatabaseHandler database = new DatabaseHandler(getActivity().getBaseContext()); 
     dictionary.linkDatabase(database); 
     dictionary.setWordList(); 
     bundle = new Bundle(); 
     bundle.putSerializable("Dictionary", dictionary); 


     return null; 
    } 

    @Override 
    protected void onPostExecute(Void result){ 
     if(progressDialog != null && progressDialog.isShowing()){ 
      progressDialog.dismiss(); 
      progressDialog = null; 
     } 

     Intent intent = new Intent(context, WordFinderActivity.class); 
     intent.putExtra("Bundle", bundle); 
     context.startActivity(intent); 
    } 
} 

} 

但是每当它尝试启动活动,它没有错误突然死机,但我没有设法找到一个错误的地方,说字典是不是序列化的,但它是:

public class Dictionary implements Serializable { 
    private ArrayList<Word> words; 
    public DatabaseHandler database; 
/**' 
* Creates a new Dictionary object with the list of words from the text file (from the database.txt once done transferring) 
* @throws IOException 
*/ 
public Dictionary() { 

} 

/** 
* Returns the list of words 
* @return the list of words 
*/ 
public ArrayList<Word> getWordList() { 
    return this.words; 
} 

/** 
* Returns the word at the specified index in the dictionary 
* @param index the index of the dictionary 
* @return the word at the specified index 
*/ 
public String getWordAtIndex(int index) { 
    Object[] wordArray = this.words.toArray(); 

    return wordArray[index - 1].toString(); 
} 

/** 
* Returns the base word score for the specified word 
* @param word the word to get the base word score for 
* @return the base word score for the specified word 
*/ 
public int getBaseWordScore(String word) { 
    int totalScore = 0; 
    String[] letters = word.split(""); 

    for (String letter : letters) { 
     if (!letter.equals("")) { 
      int letterScore; 
      letterScore = this.getLetterScore(letter); 
      totalScore += letterScore; 
     } 
    } 

    return totalScore; 
} 

public boolean isWordOfficial(String word){ 
    return this.database.getWord(word).isWordOfficial(); 
} 

/** 
* Returns the letter score for the specified letter 
* @param letter the letter to get the letter score for 
* @return the letter score for the specified letter 
*/ 
public int getLetterScore(String letter) { 
    int score = 0; 

    if("eaionrtlsu".contains(letter)){ 
     score = 1; 
    } else if("dg".contains(letter)){ 
     score = 2; 
    } else if("bcmp".contains(letter)){ 
     score = 3; 
    } else if("fhvwy".contains(letter)){ 
     score = 4; 
    } else if("k".contains(letter)){ 
     score = 5; 
    } else if("jx".contains(letter)){ 
     score = 8; 
    } else if("qz".contains(letter)){ 
     score = 10; 
    } 

    return score; 
} 

public void linkDatabase(DatabaseHandler database){ 
    this.database = database; 
} 

public void setWordList(){ 
    this.words = this.database.getAllWords(); 
} 
} 

我只是想不通,为什么它不会工作。

+0

我会想象它是'Dictionary'类中的'DatabaseHandler'这就是问题所在。 –

+0

这很奇怪,因为它以前从来都不是问题......我会看看。 –

回答

0

在调用其他函数之前调用setWordList()吗?如果不是ArrayList的话将是空的