简体   繁体   中英

New to android studio and java, stuck with an error I can't fix

I am working with this tutorial , and I got stuck.

I get an error on openSettings(); and openSearch(); the program says

can not resolve method

Could anyone please tell me what have I done wrong?

@Override
 public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_settings) {
        openSetting();
        return true;
    } else if (item.getItemId() == R.id.action_search) {
        openSearch();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

If I had to guess I think you are following example from here: https://github.com/arun-gupta/android-samples/blob/master/HelloWorldProject/HelloWorld/src/main/java/name/arungupta/android/helloworld/MainActivity.java

To solve your problem you need to a add these two methods in your class:

    private void openSettings() {
    Intent intent = new Intent(this, SettingsActivity.class);
    intent.putExtra(SETTINGS_MESSAGE, "Settings");
    startActivity(intent);
}

private void openSearch() {
    Intent intent = new Intent(this, SearchActivity.class);
    intent.putExtra(SEARCH_MESSAGE, "Search Now");
    startActivity(intent);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM