Clicking a button does not switch to a new window, but terminates the application with an error

button_setting = (Button) findViewById(R.id.button_setting); button_setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, Activity_setting.class); startActivity(intent); } }); 

Manifesto:

 <activity android:name=".Activity_setting" android:label="@string/title_activity_setting" android:parentActivityName=".MainActivity"> // // android:name="android.support.PARENT_ACTIVITY" // android:value="ru.life.sendremedylite.MainActivity" /> </activity> 

10-12 11: 09: 05.937 2041-2041 / ru.life.sendremedylite E / AndroidRuntime: FATAL EXCEPTION: main java.lang.NoSuchMethodError: ru.life.sendremedylite.Activity_setting.getActionBar at ru.life.sendremedylite.AAAA_Activity_setting.getActionBar at ru.life.sendremedylite.AAAA_AAccore (Activity_setting.java:15) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:1611) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 1663) at android.app.ActivityThread.access $ 1500 (ActivityThread.java:117) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:931) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:130) at android.app.ActivityThread.main (ActivityThread.java=683) at java.lang.reflect.Method.invokeNative (Native Method) at java.lang.reflect .Method.invoke (Method.java:507) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:839) at com.android.internal.os .ZygoteInit.main (ZygoteInit.java Dep97) at dalvik.system.NativeStart.main (Native Method)

 package ru.life.sendremedylite; import android.os.Build; import android.os.Bundle; import android.app.Activity; import android.support.annotation.RequiresApi; public class Activity_setting extends Activity { @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_setting); getActionBar().setDisplayHomeAsUpEnabled(true); } 

}

  • Please describe the mistake, too, so that we do not guess here. What an exception, log, that's all. - etki
  • in android studio does not produce errors, gives an error when testing on the phone itself - Alexey Fedorov
  • On the 6 axis falls? - Yuriy SPb
  • I'm doing on 2.3.3 on the phone on which I'm testing 5.02 - Alexey Fedorov
  • 3
    In logcat there is always a stacktrace error. Show it. - Vladyslav Matviienko

2 answers 2

The exception java.lang.NoSuchMethodError literally says that “ such a method was not found ” and is generated in cases when it is impossible to find the method that you call.

Using ActionBar on low APIs is possible ( in particular ) using the AppCompat library and its AppCompatActivity class (in which, instead of the getActionBar() method, the getSupportActionBar() method getSupportActionBar() similar purpose).

To solve this problem, you can inherit your Activity_setting from AppCompatActivity :

 public class Activity_setting extends AppCompatActivity { ... } 

and replace the getActionBar() method with getSupportActionBar() .

    It is worth checking in this place of the Activity_setting code:

     ru.life.sendremedylite.Activity_setting.onCreate(Activity_setting.java:15) 

    Also try increasing the Compile SDK version and Target SDK version in build.gradle to 21 or higher.

    • I need to api 10 - Alexey Fedorov