为什么我的selectChapterValue(String bookName)阻止我的程序工作

时间:2014-01-26 01:50:48

标签: android

"我的代码工作正常,直到我添加selectChapterValue(String bookName)方法,然后代码不起作用,我得到你的程序已停止工作的消息我已经通过这个网站,并找不到答案可以有人看了看这个方法,看看他们是否可以帮我解决这个问题。"

    public void selectChapterValue(String bookName){
        if(bookName.equals("Genesis")){chapterValue= 50;}
        else if (bookName.equals("Exodus") ) {chapterValue = 40;}
        else if (bookName.equals("Leviticus" )) {chapterValue = 27;}
        else if (bookName.equals("Numbers" )) {chapterValue = 36;}
        else if (bookName.equals("Deuteronomy" )) {chapterValue = 34;}
        else if (bookName.equals("Joshua" )) {chapterValue = 24;}
        else if (bookName.equals("Judges" )) {chapterValue = 21;}
        else if (bookName.equals("Ruth" )) {chapterValue = 4;}
        else if (bookName.equals("1 Samuel" )) {chapterValue= 31;}
        else if (bookName.equals("2 Samuel" )) {chapterValue= 24;}
        else if (bookName.equals("1 Kings" )) {chapterValue= 22;}
        else if (bookName.equals("2 Kings") ) {chapterValue= 25;}
        else if (bookName.equals("1 Chronicles" )) {chapterValue= 29;}
        else if (bookName.equals("2 Chronicles" )) {chapterValue= 36;}
        else if (bookName.equals("Ezra" )) {chapterValue= 10;}
        else if (bookName.equals("Nehemiah") ) {chapterValue= 13;}
        else if (bookName.equals("Esther") ) {chapterValue= 10;}
        else if (bookName.equals("Job") ) {chapterValue= 42;}
        else if (bookName.equals("Psalms") ) {chapterValue= 150;}
        else if (bookName.equals("Proverbs") ) {chapterValue= 31;}
        else if (bookName.equals("Ecclesiastes") ) {chapterValue= 12;}
        else if (bookName.equals("Song of Solomon") ) {chapterValue= 8;}
        else if (bookName.equals("Isaiah") ) {chapterValue= 66;}
        else if (bookName.equals("Jeremiah") ) {chapterValue= 52;}
        else if (bookName.equals("Lamentations") ) {chapterValue= 5;}
        else if (bookName.equals("Ezekiel") ) {chapterValue= 48;}
        else if (bookName.equals("Daniel") ) {chapterValue= 12;}
        else if (bookName.equals("Hosea") ) {chapterValue= 14;}
        else if (bookName.equals("Joel" )) {chapterValue= 3;}
        else if (bookName.equals("Amos") ) {chapterValue= 9;}
        else if (bookName.equals("Obadiah") ) {chapterValue= 1;}
        else if (bookName.equals("Jonah" )) {chapterValue= 4;}
        else if (bookName.equals("Micah") ) {chapterValue= 7;}
        else if (bookName.equals("Nahum") ) {chapterValue= 3;}
        else if (bookName.equals("Habakkuk" )) {chapterValue= 3;}
        else if (bookName.equals("Zephaniah") ) {chapterValue= 3;}
        else if (bookName.equals("Haggai") ) {chapterValue= 2;}
        else if (bookName.equals("Zechariah") ) {chapterValue= 14;}
        else if (bookName.equals("Malachi") ) {chapterValue= 4;}
        else if (bookName.equals("Matthew") ) {chapterValue= 28;}
        else if (bookName.equals("Mark" )) {chapterValue= 16;}
        else if (bookName.equals("Luke") ) {chapterValue= 24;}
        else if (bookName.equals("John") ) {chapterValue= 21;}
        else if (bookName.equals("Acts") ) {chapterValue= 28;}
        else if (bookName.equals("Romans" )) {chapterValue= 16;}
        else if (bookName.equals("1 Corinthians") ) {chapterValue= 16;}
        else if (bookName.equals("2 Corinthians" )) {chapterValue= 13;}
        else if (bookName.equals("Galatians" )) {chapterValue= 6;}
        else if (bookName.equals("Ephesians" )) {chapterValue= 6;}
        else if (bookName.equals("Philippians" )) {chapterValue= 4;}
        else if (bookName.equals("Colossians") ) {chapterValue= 4;}
        else if (bookName.equals("1 Thessalonians") ) {chapterValue= 5;}
        else if (bookName.equals("2 Thessalonians") ) {chapterValue= 3;}
        else if (bookName.equals("1 Timothy") ) {chapterValue= 6;}
        else if (bookName.equals("2 Timothy") ) {chapterValue= 4;}
        else if (bookName.equals("Titus") ) {chapterValue= 3;}
        else if (bookName.equals("Philemon") ) {chapterValue= 1;}
        else if (bookName.equals("Hebrews") ) {chapterValue= 13;}
        else if (bookName.equals("James") ) {chapterValue= 5;}
        else if (bookName.equals("1 Peter") ) {chapterValue= 5;}
        else if (bookName.equals("2 Peter") ) {chapterValue= 3;}
        else if (bookName.equals("1 John") ) {chapterValue= 5;}
        else if (bookName.equals("2 John") ) {chapterValue= 1;}
        else if (bookName.equals("3 John") ) {chapterValue= 1;}
        else if (bookName.equals("Jude" )) {chapterValue= 1;}
        else if (bookName.equals("Revelation" )) {chapterValue= 22;}    
        else{};
    }

1 个答案:

答案 0 :(得分:0)

看起来你应该使用一个hashmap,其中章节名称作为键,而int作为值。所以调用将是chapters.get(bookname)。

除此之外,id建议从

转动你的等号语句
bookname.equals("Jonah")

"Jonah".equals(bookname)

这可以防止nullpointer,这是我怀疑你的应用程序崩溃的原因