渲染期间引发的异常:android.support.design.widget.CoordinatorLayout无法转换为android.view.ViewGroup [英] Exception raised during Rendering: android.support.design.widget.CoordinatorLayout cannot be cast to android.view.ViewGroup

查看:451
本文介绍了渲染期间引发的异常:android.support.design.widget.CoordinatorLayout无法转换为android.view.ViewGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我之前已经获得过预览,但是我没有对文件进行任何更改.事实上,我的代码没有太多更改,只是应用程序中的确定"按钮. 只是告诉我,我从activity_main.xml文件中的设计中删除了工具栏.但是之后请撤消更改,因为我可以在MainActivity.java文件中看到它. 我是android studio的新手,任何帮助都将是有用的. 这是我的Java文件.

Although i was getting preview before, i have not made any changes in the files. As a matter of fact there is not much to change in my code, its just a OK button in app. Just to tell, i deleted the toolbar from my design in activity_main.xml file.But undo the changes afterwards as i can see it in MainActivity.java file. I am a newbie to android studio, any help would be useful. Here's my java file.

package com.learning.pehlaapp;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

public class SampleActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).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.menu_sample, 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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

推荐答案

Exception raised during Rendering:    
android.support.design.widget.CoordinatorLayout cannot be cast to 
android.view.ViewGroup 

As error said coordinatorLayout can not br cast to ViewGroup Please check your   
XML view as you uses FloatingActionButton which are define under  
CoordinatorLayout and that layout treated as ViewGroup in Activty  thus this 
exception arised

这篇关于渲染期间引发的异常:android.support.design.widget.CoordinatorLayout无法转换为android.view.ViewGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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