简体   繁体   English

Android Studio和Java的新手,卡住了一个我无法修复的错误

[英]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(); 我在openSettings();上收到错误openSettings(); and openSearch(); 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 如果我不得不猜测,我认为您是从下面的示例开始的: 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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