Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: Java exception was raised during method invocation

I got an error when js invoke Android

Uncaught Error: Java exception was raised during method invocation

,this is the js code:

window.SearchActivity.getClickData();

,this is the Android code:

mAtlasWebView.addJavascriptInterface(new SearchActivity(), "SearchActivity");
@JavascriptInterface
public void getClickData() {
    String mSearchText = mSearchEdit.getText().toString().trim();
    mvpPresenter.getClickData(mSearchText, 1);
}
like image 417
ChrongLiu Avatar asked Aug 11 '26 23:08

ChrongLiu


1 Answers

Simply add the error handler to Java void:

public void getClickData() {
    try {
        String mSearchText = mSearchEdit.getText().toString().trim();
        mvpPresenter.getClickData(mSearchText, 1);
    } catch (Exception e) {}
}
like image 179
hcj Avatar answered Aug 14 '26 22:08

hcj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!