RecyclerView在启动应用程序时崩溃

时间:2015-07-18 09:26:09

标签: android android-recyclerview

我最近开始了android开发。我开始使用RecyclerViews。但是在按照教程后我才开始工作。但在向其添加更多信息后,它开始崩溃。我似乎无法弄清楚,希望这些网站的有经验的用户可以帮助我。

崩溃日志

        07-18 02:19:23.376  12975-12975/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
    07-18 02:19:23.717  12975-12982/com.austinerck.projectteamwork I/art﹕ Background sticky concurrent mark sweep GC freed 2838(236KB) AllocSpace objects, 0(0B) LOS objects, 28% free, 807KB/1135KB, paused 8.003ms total 31.172ms
    07-18 02:19:23.855  12975-12982/com.austinerck.projectteamwork I/art﹕ Background partial concurrent mark sweep GC freed 589(76KB) AllocSpace objects, 0(0B) LOS objects, 51% free, 954KB/1978KB, paused 6.145ms total 48.881ms
    07-18 02:19:23.866  12975-12998/com.austinerck.projectteamwork D/OpenGLRenderer﹕ Render dirty regions requested: true
    07-18 02:19:23.870  12975-12975/com.austinerck.projectteamwork D/﹕ HostConnection::get() New Host Connection established 0xa6c54ad0, tid 12975
    07-18 02:19:23.884  12975-12975/com.austinerck.projectteamwork D/Atlas﹕ Validating map...
    07-18 02:19:23.946  12975-12998/com.austinerck.projectteamwork D/﹕ HostConnection::get() New Host Connection established 0xa6c54dc0, tid 12998
    07-18 02:19:23.961  12975-12998/com.austinerck.projectteamwork I/OpenGLRenderer﹕ Initialized EGL, version 1.4
    07-18 02:19:23.967  12975-12998/com.austinerck.projectteamwork D/OpenGLRenderer﹕ Enabling debug mode 0
    07-18 02:19:23.979  12975-12998/com.austinerck.projectteamwork W/EGL_emulation﹕ eglSurfaceAttrib not implemented
    07-18 02:19:23.979  12975-12998/com.austinerck.projectteamwork W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6cb5ce0, error=EGL_SUCCESS
    07-18 02:19:24.071  12975-12975/com.austinerck.projectteamwork I/art﹕ Alloc sticky concurrent mark sweep GC freed 122(17KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 998KB/1978KB, paused 1.563ms total 17.553ms
    07-18 02:19:24.095  12975-12975/com.austinerck.projectteamwork I/art﹕ Alloc partial concurrent mark sweep GC freed 39(2256B) AllocSpace objects, 0(0B) LOS objects, 50% free, 996KB/2020KB, paused 1.319ms total 19.319ms
    07-18 02:19:24.130  12975-12975/com.austinerck.projectteamwork I/art﹕ Alloc concurrent mark sweep GC freed 13(12KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 984KB/2008KB, paused 3.235ms total 25.851ms
    07-18 02:19:24.133  12975-12975/com.austinerck.projectteamwork I/art﹕ Forcing collection of SoftReferences for 71MB allocation
    07-18 02:19:24.151  12975-12975/com.austinerck.projectteamwork I/art﹕ Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 50% free, 984KB/2008KB, paused 1.061ms total 18.133ms
    07-18 02:19:24.157  12975-12975/com.austinerck.projectteamwork E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 74649612 byte allocation with 1048576 free bytes and 63MB until OOM"
    07-18 02:19:24.158  12975-12975/com.austinerck.projectteamwork D/skia﹕ --- allocation failed for scaled bitmap
    07-18 02:19:24.158  12975-12975/com.austinerck.projectteamwork D/AndroidRuntime﹕ Shutting down VM
    07-18 02:19:24.159  12975-12975/com.austinerck.projectteamwork E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.austinerck.projectteamwork, PID: 12975
        android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.ImageView
                at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                at com.austinerck.projectteamwork.ProjectsListAdapter.onCreateViewHolder(ProjectsListActivity.java:104)
                at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:4121)
                at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3431)
                at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3340)
                at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1810)
                at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1306)
                at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1269)
                at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:523)
                at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1988)
                at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2237)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:562)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:493)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                at android.view.View.layout(View.java:15596)
                at android.view.ViewGroup.layout(ViewGroup.java:4966)
                at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2072)
                at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1829)
                at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
                at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
                at android.view.Choreographer.doCallbacks(Choreographer.java:580)
                at android.view.Choreographer.doFrame(Choreographer.java:550)
                at android.view.Choreographer$Fram

ProjectsListActivity.java

package com.austinerck.projectteamwork;

import android.support.v4.widget.SwipeRefreshLayout;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;


public class ProjectsListActivity extends AppCompatActivity {

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

        //Creates objects for RecyclerView
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.projects_list_recyclerview);


        //Create layout manager for RecyclerView
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(new ProjectsListAdapter());


        //Sets up SwipeRefreshLayout
        final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.projects_list_swipe_refresh_layout);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                //TODO: Refresh code here
                swipeRefreshLayout.setRefreshing(false);
            }
        });
        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_dark,
                android.R.color.holo_green_dark,
                android.R.color.holo_orange_dark,
                android.R.color.holo_red_dark);

    }

    @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_projects_list, 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();

        switch(id){
            case R.id.action_sort:
                Shortcut.toast(this,"Coming Soon");
                break;
            case R.id.action_refresh:
                //TODO: Refresh code here
                break;
            case R.id.action_settings:
                Shortcut.toast(this,"Coming Soon");
                break;
            case R.id.action_feedback:
                Shortcut.toast(this,"Coming Soon");
                break;
            case R.id.action_help:
                Shortcut.toast(this,"Coming Soon");
                break;
            default:
                Shortcut.toast(this,"ERROR: Unknown Action");
                break;
        }

        return super.onOptionsItemSelected(item);
    }
}

class ProjectsListAdapter extends RecyclerView.Adapter{

    ArrayList<ProjectDetails> projectDetails = new ArrayList<>();

    public ProjectsListAdapter(){
        //Sets values in projectDetails
        projectDetails.add(new ProjectDetails(NasaProjects.GEMINI));
        projectDetails.add(new ProjectDetails(NasaProjects.APOLLO));
        projectDetails.add(new ProjectDetails(NasaProjects.ISS));
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        //Gets the view as an object
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_projects_card, viewGroup, false);

        //Gets TextViews as objects to pass them to ProjectsListView
        /*TextView name = (TextView) view.findViewById(R.id.project_detail_name);
        TextView owner = (TextView) view.findViewById(R.id.project_detail_owner);
        TextView desc = (TextView) view.findViewById(R.id.project_detail_desc);*/

        return new ProjectsListView(view/*, name, owner, desc*/);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        ProjectsListView view = (ProjectsListView) viewHolder;
        /*view.name.setText(projectDetails.get(i).getName());
        view.owner.setText(projectDetails.get(i).getOwner());
        view.desc.setText(projectDetails.get(i).getDesc());*/

    }

    @Override
    public int getItemCount() {
        return projectDetails.size();
    }

    class ProjectsListView extends RecyclerView.ViewHolder{

        View view;
        //TextView name, owner, desc;

        public ProjectsListView(View view/*, TextView name, TextView owner, TextView desc*/){
            super(view);
            this.view = view;
            /*this.name = name;
            this.owner = owner;
            this.desc = desc;*/
        }

    }
}

class ProjectDetails{

    private String name, owner, desc;

    public ProjectDetails(NasaProjects nasaProjects){
        name = nasaProjects.getName();
        owner = nasaProjects.getOwner();
        desc = nasaProjects.getDesc();

    }

    public String getName() {
        return name;
    }

    public String getOwner() {
        return owner;
    }

    public String getDesc() {
        return desc;
    }
}

activity_projects_list.xml

<LinearLayout
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:orientation="vertical"
tools:context=".ProjectListActivity">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/projects_list_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/projects_list_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/material_margin"
        android:paddingRight="@dimen/material_margin"></android.support.v7.widget.RecyclerView>

</android.support.v4.widget.SwipeRefreshLayout>

fragment_projects_card.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/material_margin"
    android:padding="@dimen/material_padding"
    android:elevation="@dimen/material_elevation"
    card_view:cardCornerRadius="@dimen/material_corner_radius">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/projects_list_item_background"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="@dimen/material_padding_border"
            android:paddingRight="@dimen/material_padding"
            android:paddingBottom="@dimen/material_padding"
            android:paddingLeft="@dimen/material_padding">

            <TextView
                android:id="@+id/project_detail_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/material_title_size"
                android:textColor="@color/material_title_color"
                android:text="Title goes here"/>

            <TextView
                android:id="@+id/project_detail_owner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/material_subtitle_size"
                android:textColor="@color/material_subtitle_color"
                android:text="Subtitle here"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingRight="@dimen/material_padding"
            android:paddingBottom="@dimen/material_padding_border"
            android:paddingLeft="@dimen/material_padding">

            <TextView
                android:id="@+id/project_detail_desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/material_content_size"
                android:textColor="@color/material_content_color"
                android:text="Hello World! If you are seeing this text an error must of occured!"/>

        </LinearLayout>

    </LinearLayout>

</android.support.v7.widget.CardView>

0 个答案:

没有答案