Challenge 8: App crashes

Hi.

When i try run app, it is crashes with exception:

FATAL EXCEPTION: main
Process: com.example.ad.criminalintent, PID: 4371
java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of ‘android.support.v4.content.res.ResourcesCompat’ appears in /data/app/com.example.ad.criminalintent-KiHzbfpRvRV_aLtpI0VbDA==/split_lib_dependencies_apk.apk)
at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:81)
at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:71)
at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:67)
at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753)
at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)
at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)
at android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621)
at android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.ad.criminalintent.SingleFragmentActivity.onCreate(SingleFragmentActivity.java:18)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Activity.performCreate(Activity.java:6991)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Exception occurred in SingleFragmentActivity.onCreate in setContentView(R.layout.activity_fragment); string,
but i writing all how in book primer:

public abstract class SingleFragmentActivity extends AppCompatActivity {
    protected abstract Fragment createFragment();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);

        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_container);

        if(fragment == null) {
            fragment = createFragment();
            fm.beginTransaction()
                    .add(R.id.fragment_container, fragment)
                    .commit();
        }

    }
}

What i do wrong?

Check and try to update the dependency Libraries. In build.gradle file must be-

compile 'com.android.support:appcompat-v7:25.3.1’
compile ‘com.android.support:recyclerview-v7:25.3.1’

see more info at RecyclerView creates dependencies problem

I was able to fix the problem by changing in my build.gradle file:
(заменил строки созданные автоматически на следующие: )

com.android.support:appcompat-v7:26.1.0
com.android.support:recyclerview-v7:26.1.0

it working now, thanks :slight_smile:

1 Like

I had the same problem. It seems like Android Studio 3.0.1 creates a new app with appcompat-v7:26.1.0 in the app/build.gradle file. It also has the following in build.gradle

compileSdkVersion 26

targetSdkVersion 26

When I added the new dependency, Android Studio added recyclerview-v7:27.0.1 to the app/build.gradle file.

So there is a mismatch of some sort going on there.

When I changed

implementation 'com.android.support:recyclerview-v7:27.0.1'

to

implementation 'com.android.support:recyclerview-v7:26.1.0'

everything started working again.

I’ve been searching for this forum for three days. I’ve deleted this program twice trying to find a run time error. I hope this work for me too.