Android Studio中的NoSuchFieldError。
运行其他应用程序时也会出现此问题。我也尝试使用其他应用程序。 请帮帮我,我无法弄清楚这个错误是怎么来的。在这里,我想制作一个包含一些菜单项的工具栏。
错误: -
java.lang.NoSuchFieldError: No static field title of type I in class
Landroid/support/v7/appcompat/R$id; or its superclasses (declaration of
'android.support.v7.appcompat.R$id' appears in
/data/app/com.example.manojbudhaayer.newapplicaton-2/split_lib_slice_2_apk.apk)
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id ==R.id.profile){
return true;
}
if (id == R.id.setting){
return true;
}
if (id == R.id.mylink){
return true;
}
if (id == R.id.refresh){
return true;
}
return true;
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="com.example.manojbudhaayer.newapplicaton.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
></android.support.v7.widget.Toolbar>
</LinearLayout>
menu_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/profile"
android:title="Profile"
android:orderInCategory="101"
app:showAsAction="ifRoom"/>
<item android:id="@+id/setting"
android:title="Setting"
android:orderInCategory="102"
app:showAsAction="ifRoom"/>
<item android:id="@+id/mylink"
android:title="My fb Link"
android:orderInCategory="103"
app:showAsAction="ifRoom"/>
<item android:id="@+id/refresh"
android:title="Refresh"
android:orderInCategory="104"
app:showAsAction="ifRoom"/>
</menu>
style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
答案 0 :(得分:1)