我开发和Android应用程序,一切都很完美,然后我有一个简单的代码,测试和无错误,然后当我尝试测试应用程序时,我的主屏幕活动开始抛出以下3个错误:
Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class android.support.design.widget.FloatingActionButton
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.IllegalAccessError: tried to access class android.support.v7.widget.AppCompatImageHelper from class android.support.design.widget.FloatingActionButton
ActivityMainScreen.java setContentView(R.layout.activity_main_screen);
中的所有三个错误同时存在于同一行(onCreate()
)中,问题是我所拥有的代码是一种不同的活动,甚至与主要的相关,所以我不知道它可能是什么,希望你能提供帮助,这是错误的代码:
activity_main_screen.xml:
<RelativeLayout
android:id="@+id/Container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="true"
android:background="#fff"
android:paddingTop="50dp"></RelativeLayout>
<android.support.design.widget.AppBarLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="2dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
app:elevation="2dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/primary_dark_material_dark"
android:layout_above="@+id/content_frame"
android:layout_alignParentStart="true">
<ImageButton
android:id="@+id/Sort"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_action_filter"
android:background="@color/transparent"
android:layout_gravity="right"
android:layout_marginEnd="10dp"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_marginEnd="15dp"
android:layout_marginBottom="15dp"
android:src="@drawable/ic_add_white_24dp"
app:fabSize="normal"
app:backgroundTint="@color/colorPrimary"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
MainScreenActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main_screen);
tagTitles = getResources().getStringArray(R.array.navigation_array);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerList = (ListView) findViewById(R.id.left_drawer);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.bringToFront();
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.bringToFront();
Sort = (ImageView) findViewById(R.id.Sort);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainScreenActivity.this,CreateWorkout.class);
startActivityForResult(i,1);
}
});
ArrayList<DrawerItem> items = new ArrayList<DrawerItem>();
items.add(new DrawerItem(tagTitles[0],R.mipmap.home));
items.add(new DrawerItem(tagTitles[1],R.mipmap.acrobatics));
items.add(new DrawerItem(tagTitles[2],R.mipmap.profile));
drawerList.setAdapter(new DrawerListAdapter(this, items));
drawerList.setOnItemClickListener(new DrawerItemClickListener());
// Crear ActionBarDrawerToggle para la apertura y cierre
// drawerToggle.setDrawerIndicatorEnabled(false);
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.setTitle("Home");
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (drawerLayout.isDrawerOpen(drawerList)){
drawerLayout.closeDrawer(drawerList);
}
else
drawerLayout.openDrawer(drawerList);
}
});
if (savedInstanceState == null) {
selectItem(0);
}
Sort.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new MaterialDialog.Builder(MainScreenActivity.this)
.title(R.string.filtertitle)
.items(R.array.filter_items)
.itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
if (which != -1){
Fragment currentFragment = fragmentManager.findFragmentById(R.id.content_frame);
if (currentFragment instanceof MainFragment) {
((MainFragment) currentFragment).Task(text.toString());
//place your filtering logic here using currentFragment
}
}
return true;
}
})
.positiveText(R.string.choose)
.show();
}
});
}