Android 获取错误java.lang.NoSuchMethodError:没有静态方法getFont。。。重写XML文件后
我试图在github上上载我的工作项目,但未能上载XML文件,并且不知何故丢失了它们,因为我以前从未使用过github,现在当我为我的项目重新编写XML文件时,编译器会出现以下错误:Android 获取错误java.lang.NoSuchMethodError:没有静态方法getFont。。。重写XML文件后,android,android-studio,Android,Android Studio,我试图在github上上载我的工作项目,但未能上载XML文件,并且不知何故丢失了它们,因为我以前从未使用过github,现在当我为我的项目重新编写XML文件时,编译器会出现以下错误: java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface
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.syyam.dietplan-1/base.apk)
我已为此寻找解决方案,并找到了此解决方案,但对我无效:
我的应用程序级渐变文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.syyam.dietplan"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.firebaseui:firebase-ui-database:0.4.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.jjoe64:graphview:4.2.2'
testImplementation 'junit:junit:4.12'
}应用插件:“com.google.gms.google服务”
编辑:my launcher acctivity的xml文件是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EEG">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="19dp"
android:text="Alpha "
/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="12"
android:layout_marginLeft="5dp"
android:id="@+id/mSeekAlpha"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/alphaCount"
android:text="0.0"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="18dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="20dp"
android:text="Beta "/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="12"
android:layout_marginLeft="5dp"
android:id="@+id/mSeekBeta"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/betaCount"
android:text="0.0"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="18dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="20dp"
android:text="Delta "/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="12"
android:layout_marginLeft="5dp"
android:id="@+id/mSeekDelta"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/deltaCount"
android:text="0.0"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="18dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="20dp"
android:text="Theta "/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="12"
android:layout_marginLeft="5dp"
android:id="@+id/mSeekTheta"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/thetaCount"
android:text="0.0"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="18dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="19dp"
android:text="Gamma"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="12"
android:layout_marginLeft="5dp"
android:id="@+id/mSeekGamma"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/gammaCount"
android:text="0.0"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="18dp"
/>
</LinearLayout>
<Button
android:id="@+id/subBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@color/colorPrimaryDark"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Submit"
android:textColor="@android:color/background_light"
android:textSize="16dp"
android:textStyle="bold"
/>
</LinearLayout>
</RelativeLayout>
清单看起来是这样的:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.syyam.dietplan">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".EEG">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity" />
<activity android:name=".RegisterActivity" />
<activity android:name=".Suffering" />
<activity android:name=".DisorederWebView" />
<activity android:name=".ChoosePlan" />
<activity android:name=".Schedule" />
<activity android:name=".DailyAppContent" />
<activity android:name=".WeeklyAppContent" />
<activity android:name=".MonthlyAppContent" />
<activity android:name=".OverallSchedule" />
<activity android:name=".WeeklyDailyAppContent" />
<activity android:name=".MonthlyDailyAppContent" />
<activity android:name=".chooseTestType" />
<activity android:name=".history" />
<activity android:name=".MainActivity" />
</application>
</manifest>
因此,我通过删除手动更正了它们。问题是,您的buildtoolsversion主版本号27.x.x与应用程序build.gradle文件中的编译器DKVersion 26不相同
每个sdk发行版都有一个专门针对该sdk的buildtools发行版,并且它们通常没有后端口,因此您的buildtools 27.x.x不知道如何使用sdk 26进行构建。Android Studio应该会显示一个lint警告,突出显示错误。那么您丢失了res文件夹中的所有内容?你的清单文件呢?你能发布导致此错误的xml文件吗?不,我没有丢失所有内容,我已经将我的整个项目(以前的版本)上传到github上,这些文件是安全的。在最近的上传之后,我只丢失了我制作的新XML文件,我的新java文件也被破坏了。@Sub6Resources我上传了启动程序XML文件。请检查。@flopshot有效,所以诀窍是使用最新的构建版本,对吗?将compileSdkVersion从26更新到27,并将“com.android.support”更新到27.1.1对我有效,