-2

I can't seem to get to the bottom of this. Using Apache POI to read excel files. Seem to be hitting errors. Making app force close.

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

Full error output

My XML android:onClick id has the same name as my method listener:

 <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();
    }
}

This is seemingly where the errors come up in this method but I can't see why.

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' is defined at the top of the class globally without instantiation and then defined in onCreate as:

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

Any help is appreciated, let me know what other information you need, I'm also getting some other issue with I/art rejecting re-init on previously-failed classes. See link below if you think the two issues may be linked.

I/art rejection

  • I presume the only reason why it's been downvoted is because it's such an 'easy fix', if it were so, why, instead of downvoting and leaving the page, don't you downvote, answer the question then leave. I've looked at other similar answers, checked my code for similar instances and tried those fixes and it hasn't resolved anything. – Chris Connolly Feb 08 '17 at 18:59

2 Answers2

1

You can't change the method signature at all- including the throws declaration. You need to catch that IOException that means, even if you respond by rethrowing (in which case you will crash).

I'm also assuming that function is in your activity class. If not, that's also a problem.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

Replacing Apache POI with Android5Xlsx Project jar files fixed my issues. Can now read/write excel files without any errors. Simple and easy fix. Conclusion: Apache POI is a pain in the ass.