2017-02-08 14 views
-2

私はこれの最下部にいるようです。 Apache POIを使用してファイルを読み取る誤りを犯すと思われる。アプリを強制的に閉じる。Androidのメソッドonroid:onClickを実行できませんでした

java.lang.IllegalStateException: Could not execute method for android:onClick 

Full error output

マイXMLのアンドロイド:onClickのidは私のメソッドリスナーと同じ名前を持つ:

<Button 
    android:text="OK" 
    android:id="@+id/submitOK" 
    android:textAlignment="center" 
    android:textAppearance="@style/TextAppearance.AppCompat.Caption" 
    android:textSize="12sp" 
    android:background="@drawable/round_button" 
    android:gravity="center_vertical|center_horizontal" 
    android:textColor="#fff" 
    android:layout_alignTop="@+id/setName" 
    android:layout_toRightOf="@+id/setName" 
    android:layout_marginLeft="5dp" 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:layout_alignBottom="@+id/setName" 
    **android:onClick="inRoster"** 
    android:visibility="gone" 
/> 

public void inRoster(View v) throws IOException { 
    if (checkValidinFile()) { 
     // Send to a new page that lists your shifts, what time you want your alarms 
     // and what time you want messages to be sent 
     // What time do you want to send the messages? 
     // What time do you want your alarms to be? 
     // Do all alarm and message sending bs 
    } else { 
     // Display a toast message saying name not found 
     // Clear contents of the editbox for the name for user to re enter 
     CharSequence text = "Name not found in Roster!"; 
     setName.setText(""); 
     int duration = Toast.LENGTH_SHORT; 
     Toast.makeText(this, text, duration).show(); 
    } 
} 

エラーは、この方法で出てくるけどここは一見です理由を見ることができません。

public boolean checkValidinFile() throws IOException { 
    String nameToMatch = setName.getText().toString().toLowerCase(); 

    try { 
     InputStream ExcelFileToRead = new FileInputStream(roster); 
     XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead); 
     XSSFSheet sheet = wb.getSheetAt(0); 

     Iterator<Row> iterator = sheet.iterator(); 

     while (iterator.hasNext()) { 

      Row currentRow = iterator.next(); 
      Iterator<Cell> cellIterator = currentRow.iterator(); 
      while (cellIterator.hasNext()) { 

       Cell currentCell = cellIterator.next(); 
       System.out.println(currentCell.toString() + " "); 
      } 
     } 
     System.out.println(); 

     wb.close(); 
     ExcelFileToRead.close(); 
    } 
    catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return true; 
} 

が「SetNameメソッド」インスタンス化せずに、グローバルクラスの先頭に定義され、その後のonCreateで定義されています。すべてのヘルプは高く評価され

setName = (EditText) findViewById(R.id.setName); 

、私はあなたが必要とする他のどのような情報を知らせ、I以前に失敗したクラスの再初期化を拒否するI/Artで他にもいくつかの問題が発生しています。 2つの問題がリンクされていると思われる場合は、下のリンクを参照してください。

I/art rejection

+0

私はdownvotedされている唯一の理由は、そのような '簡単な修正'の理由であると仮定します。なぜそうであれば、downvotingとページを離れるのではなく、downvoteしないで、私は他の同様の答えを見て、同様のインスタンスのために私のコードをチェックし、それらの修正を試みたが、何も解決していない。 –

答えて

1

あなたは宣言を投げるなど、オールでメソッドのシグネチャを変更することはできません。そのIOExceptionを捕まえる必要があります。これは、再スローされた場合でも(つまり、クラッシュする)ことを意味します。

私はまた、あなたのアクティビティクラスに関数があると仮定しています。もしそうでなければ、それも問題です。

+0

投げを取り除き、試し釣りを追加しましたが、それでも同じエラーが発生しました。いいえ運は –

+0

他のアイデア?文字列を引く –

+0

YEah、私はあなたの最初の問題を誤解しました。完全なスタックトレースを投稿すると、私はあなたが本当のエラー(常に最下位のもの)を見逃したと思います。 –

0

Apache POIをAndroid5Xlsxに置き換えるプロジェクトjarファイルが私の問題を修正しました。エラーなしでExcelファイルを読み書きできるようになりました。シンプルで簡単な修正。結論:Apache POIはお尻の痛みです。

関連する問題