以下类不能被实例化: - android.support.v7.widget.Toolbar [英] The following classes could not be instantiated: - android.support.v7.widget.Toolbar

查看:1113
本文介绍了以下类不能被实例化: - android.support.v7.widget.Toolbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造与新材料设计的应用程序在Android中使用的棒棒堂(5.0)。

I am creating an app with the new Material Design used in Android Lollipop (5.0).

我使用以下指南:

  • <一个href="http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-$p$p.html">http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-$p$p.html
  • <一个href="http://antonioleiva.com/material-design-everywhere/">http://antonioleiva.com/material-design-everywhere/
  • http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html
  • http://antonioleiva.com/material-design-everywhere/

在创建我的工具栏,我收到此错误:下面的类不能被实例化: - android.support.v7.widget.Toolbar

After I create my toolbar, I receive this error: "The following classes could not be instantiated: - android.support.v7.widget.Toolbar"

该应用程序的工作原理以及在手机或模拟器,而Android工作室的布局设计不能正确显示的布局。

The app works well in the phone or emulator, but the layout designer of Android Studio doesn't show the layout correctly.

下面有一些图片:

在my_awesome_toolbar.xml布局preVIEW错误

Error in my_awesome_toolbar.xml layout preview

在activity_my.xml布局preVIEW错误

Error in activity_my.xml layout preview

文件的XML code:

The xml code of the files:

my_awesome_toolbar.xml:

my_awesome_toolbar.xml:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />

activity_my.xml:

activity_my.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/root"
            tools:context="com.myapp.test.MyActivity"
            android:orientation="horizontal">

    <include
        android:id="@+id/toolbar"
        layout="@layout/my_awesome_toolbar"
        />
    <!-- Rest of layout -->
</RelativeLayout>

MyActivity.java:

MyActivity.java:

package com.myapp.test;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;


public class MyActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, 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 $ C $的风格C(值/ styles.xml):

xml code of the styles (values/styles.xml):

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/blue</item>
        <item name="colorPrimaryDark">@color/dark_blue</item>
        <item name="actionOverflowButtonStyle">@style/AppTheme.OverflowButtonStyle</item>
    </style>

    <!-- Style Title -->
    <style name="Title">
        <item name="android:textColor">@color/white</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">16sp</item>
    </style>

    <style name="AppTheme.OverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
        <item name="android:src">@drawable/overflow_icon</item>
    </style>
</resources>

目前,我采用Android Studio的Beta版0.8.9

At the moment I use Android Studio Beta 0.8.9

推荐答案

很抱歉,如果我的回答是我自己,但在最后,我的问题的解决方案是更新的Andr​​oid工作室到新版本0.8.14由加纳利频道:< A HREF =htt​​p://tool​​s.android.com/recent/> http://tool​​s.android.com/recent/

Sorry if I answer myself, but, at the finally, the solution of my problem was update Android Studio to the new version 0.8.14 by Canary Channel: http://tools.android.com/recent/

更新之后,问题就消失了:

After the update, the problem is gone:

在我离开这个问题在这里为那些谁拥有这个问题在未来。

I leave this question here for those who have this problem in the future.

这篇关于以下类不能被实例化: - android.support.v7.widget.Toolbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆