尝试在Android studio

时间:2018-02-13 19:48:52

标签: android logcat

当我尝试编译项目时出现以下错误;任何人都知道我能用这个错误做些什么。

  

致命的例外:主要

     

流程:com.bignerdranch.android.criminalintent,PID:15284                                                                                            java.lang.NoSuchMethodError:没有静态方法   的getFont(Landroid /内容/上下文; ILandroid / util的/的TypedValue; ILandroid /插件/ TextView的)Landroid /图形/字体或符号;   在课堂上Landroid / support / v4 / content / res / ResourcesCompat;或者它的超级   课程(宣言)   ' android.support.v4.content.res.ResourcesCompat'出现在   /data/app/com.bignerdranch.android.criminalintent-sYwk5YXA0Ap8nyn-79YvKg==/base.apk)                                                                                                在   android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)                                                                                                在   android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)                                                                                                在   android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)                                                                                                在   android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)                                                                                                在   android.support.v7.widget.AppCompatTextView。(AppCompatTextView.java:81)                                                                                                在   android.support.v7.widget.AppCompatTextView。(AppCompatTextView.java:71)                                                                                                在   android.support.v7.widget.AppCompatTextView。(AppCompatTextView.java:67)                                                                                                在android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753)                                                                                                在   android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)                                                                                                在   android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)                                                                                                在   android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621)                                                                                                在   android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631)                                                                                                在   android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)                                                                                                在   android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)                                                                                                在   android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)                                                                                                在   com.bignerdranch.android.criminalintent.SingleFragmentActivity.onCreate(SingleFragmentActivity.java:21)                                                                                                在android.app.Activity.performCreate(Activity.java:6999)                                                                                                在android.app.Activity.performCreate(Activity.java:6990)                                                                                                在   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)                                                                                                在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)                                                                                                在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)                                                                                                在android.app.ActivityThread.-wrap11(未知来源:0)                                                                                                在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1589)                                                                                                在android.os.Handler.dispatchMessage(Handler.java:106)                                                                                                在android.os.Looper.loop(Looper.java:164)                                                                                                在android.app.ActivityThread.main(ActivityThread.java:6494)                                                                                                at java.lang.reflect.Method.invoke(Native Method)                                                                                                在   com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)                                                                                                在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

以下是它在日志中失败的部分

         public abstract class SingleFragmentActivity extends AppCompatActivity

                   {
                        protected abstract Fragment createFragment();//abstract method
                          @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();
                                                        }
                                  }
}

1 个答案:

答案 0 :(得分:0)

始终尝试阅读并了解Android Studio告诉您的内容。在这种情况下,它非常清楚地告诉您在当前上下文中没有getFont()这样的方法。您可能希望/应该使用ResourcesCompat.getFont(context, R.font.your_font);,但无法知道,因为您没有发布代码示例。请查看Stack Overflow的发布指南。这将为每个人节省大量时间。