gpt4 book ai didi

java - 由 : java. lang.NoSuchFieldError : android. support.v7.appcompat 引起

转载 作者:行者123 更新时间:2023-11-30 02:27:55 25 4
gpt4 key购买 nike

使用这段代码:

package com.example.newsapp;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

private Button mTrueButton;
private Button mFalseButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mTrueButton = (Button)findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,
R.string.correct_toast,
Toast.LENGTH_SHORT).show();


}
});
mFalseButton = (Button)findViewById(R.id.true_button);
mFalseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,
R.string.incorret_toast,
Toast.LENGTH_SHORT).show();


}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);


}

}

还有这个 XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newsapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

我收到以下错误:

12-28 16:10:43.777: I/dalvikvm(13310): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
12-28 16:10:43.777: W/dalvikvm(13310): VFY: unable to resolve virtual method 11426: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
12-28 16:10:43.777: D/dalvikvm(13310): VFY: replacing opcode 0x6f at 0x0000
12-28 16:10:43.777: I/dalvikvm(13310): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
12-28 16:10:43.777: W/dalvikvm(13310): VFY: unable to resolve virtual method 11432: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
12-28 16:10:43.777: D/dalvikvm(13310): VFY: replacing opcode 0x6f at 0x0000
12-28 16:10:43.777: I/dalvikvm(13310): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
12-28 16:10:43.777: W/dalvikvm(13310): VFY: unable to resolve virtual method 9005: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
12-28 16:10:43.777: D/dalvikvm(13310): VFY: replacing opcode 0x6e at 0x000e
12-28 16:10:43.787: D/dalvikvm(13310): DexOpt: couldn't find static field Landroid/support/v7/appcompat/R$styleable;.Toolbar_buttonGravity
12-28 16:10:43.787: W/dalvikvm(13310): VFY: unable to resolve static field 3142 (Toolbar_buttonGravity) in Landroid/support/v7/appcompat/R$styleable;
12-28 16:10:43.787: D/dalvikvm(13310): VFY: replacing opcode 0x60 at 0x00aa
12-28 16:10:43.817: I/dalvikvm(13310): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
12-28 16:10:43.817: W/dalvikvm(13310): VFY: unable to resolve virtual method 364: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
12-28 16:10:43.817: D/dalvikvm(13310): VFY: replacing opcode 0x6e at 0x0002
12-28 16:10:43.817: I/dalvikvm(13310): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
12-28 16:10:43.817: W/dalvikvm(13310): VFY: unable to resolve virtual method 386: Landroid/content/res/TypedArray;.getType (I)I
12-28 16:10:43.817: D/dalvikvm(13310): VFY: replacing opcode 0x6e at 0x0002
12-28 16:10:43.827: D/AndroidRuntime(13310): Shutting down VM
12-28 16:10:43.827: W/dalvikvm(13310): threadid=1: thread exiting with uncaught exception (group=0x418eeda0)
12-28 16:10:43.827: E/AndroidRuntime(13310): FATAL EXCEPTION: main
12-28 16:10:43.827: E/AndroidRuntime(13310): Process: com.example.newsapp, PID: 13310
12-28 16:10:43.827: E/AndroidRuntime(13310): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newsapp/com.example.newsapp.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.ActivityThread.access$900(ActivityThread.java:161)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.os.Handler.dispatchMessage(Handler.java:102)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.os.Looper.loop(Looper.java:157)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.ActivityThread.main(ActivityThread.java:5356)
12-28 16:10:43.827: E/AndroidRuntime(13310): at java.lang.reflect.Method.invokeNative(Native Method)
12-28 16:10:43.827: E/AndroidRuntime(13310): at java.lang.reflect.Method.invoke(Method.java:515)
12-28 16:10:43.827: E/AndroidRuntime(13310): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
12-28 16:10:43.827: E/AndroidRuntime(13310): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
12-28 16:10:43.827: E/AndroidRuntime(13310): at dalvik.system.NativeStart.main(Native Method)
12-28 16:10:43.827: E/AndroidRuntime(13310): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:273)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
12-28 16:10:43.827: E/AndroidRuntime(13310): at com.example.newsapp.MainActivity.onCreate(MainActivity.java:18)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.Activity.performCreate(Activity.java:5426)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
12-28 16:10:43.827: E/AndroidRuntime(13310): ... 11 more
12-28 16:10:43.827: E/AndroidRuntime(13310): Caused by: java.lang.reflect.InvocationTargetException
12-28 16:10:43.827: E/AndroidRuntime(13310): at java.lang.reflect.Constructor.constructNative(Native Method)
12-28 16:10:43.827: E/AndroidRuntime(13310): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
12-28 16:10:43.827: E/AndroidRuntime(13310): ... 24 more
12-28 16:10:43.827: E/AndroidRuntime(13310): Caused by: java.lang.NoSuchFieldError: android.support.v7.appcompat.R$styleable.Toolbar_buttonGravity
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.support.v7.widget.Toolbar.<init>(Toolbar.java:203)
12-28 16:10:43.827: E/AndroidRuntime(13310): at android.support.v7.widget.Toolbar.<init>(Toolbar.java:190)
12-28 16:10:43.827: E/AndroidRuntime(13310): ... 27 more

我在网上搜索并找到了不同的“解决方案”,但没有一个对我有用。有什么建议么?对此日志的一些见解将不胜感激,当我尝试启动它时它就崩溃了

最佳答案

<强>1。将依赖项导入 Maven 仓库

如果您使用的是 Maven 和默认存储库,则 appcompat 库已过时。将库从您的 Android SDK 手动导入到您的本地存储库中,然后重试。 (旧的appcompat是508KB,Android SDK的是497KB)

要导入 jar(指定 Android SDK 的正确路径):

mvn install:install-file -Dfile=/path/to/sdk/extras/android/compatibility/v7/appcompat/libs/android-support-v7-appcompat.jar -DgroupId=com.google.android -DartifactId=support-v7-appcompat -Dversion=r21 -Dpackaging=jar

然后在您的 pom 文件中添加依赖项:

<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v7-appcompat</artifactId>
<version>r21</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

<强>2。或者查看使用 Maven Android SDK 部署程序: https://github.com/simpligility/maven-android-sdk-deployer

关于java - 由 : java. lang.NoSuchFieldError : android. support.v7.appcompat 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27677245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com