空对象引用上的'void com.algolia.instantsearch.core.helpers.Searcher.destroy()'

时间:2019-03-03 00:49:22

标签: android algolia

当我单击后退箭头以退出活动时,我的应用程序崩溃并且出现以下错误:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.algolia.instantsearch.core.helpers.Searcher.destroy()' on a null object reference

public class DiscoverActivity extends AppCompatActivity {
private DatabaseReference mFriendDatabase, mFriendDatabase2;
private FirebaseAuth mAuth;
private String mCurrent_user_id;
private GridView contacts_list;
private EditText searchBox;
private ImageButton searchButon;
private static final String ALGOLIA_APP_ID = "I_dunno";
private static final String ALGOLIA_SEARCH_API_KEY = "I_dunno";
private static final String ALGOLIA_INDEX_NAME = "user_index";

private Searcher searcher;
private InstantSearch helper;



final DatabaseReference rootref = FirebaseDatabase.getInstance().getReference();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("users");
private ArrayList<CustomContact> contactList = new ArrayList<>();




protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_findfriend);

    Searcher searcher = Searcher.create(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);
    helper = new InstantSearch(this, searcher);
    helper.search();

    mAuth = FirebaseAuth.getInstance();
    mCurrent_user_id = mAuth.getCurrentUser().getUid();



}
@Override
protected void onDestroy() {
    searcher.destroy();
    super.onDestroy();
}
}

我能够解决它。愚蠢的错误。我希望这对遇到类似问题的其他人有所帮助。注意细节。

1 个答案:

答案 0 :(得分:0)

我更改了:

Searcher searcher = Searcher.create(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);

searcher = Searcher.create(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);