2016-07-30 103 views
0

我想用我自己的自定義適配器來填補片段的Lis​​tView和我似乎當我在運行時選擇該選項卡只收到此異常。當我點擊我的事件選項卡時,導致此異常的主要原因是什麼?TransactionTooLargeException的原因?

這裏是MyAdapter類

package com.lucasmikesoftware.messaround; 

import android.content.Context; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 


public class MyAdapter extends ArrayAdapter<String> { 
public MyAdapter(Context context, String[] values) { 
    super(context, R.layout.events_past_list_item, values); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater theInflater = LayoutInflater.from(getContext()); 
    View theView = theInflater.inflate(R.layout.events_past_list_item,parent,false); 
    String itemTitle = getItem(position); 
    TextView theTextView = (TextView) theView.findViewById(R.id.text_view); 
    theTextView.setText(itemTitle); 

    ImageView theImageView = (ImageView) theView.findViewById(R.id.image_view); 
    theImageView.setImageResource(R.drawable.icon_events); 
    return theView; 
} 
} 

這裏是EventsPast類

package com.lucasmikesoftware.messaround; 


import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.ListAdapter; 
import android.widget.ListView; 


public class EventsPast extends Fragment { 


public EventsPast() { 
    // Required empty public constructor 
} 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setHasOptionsMenu(true); 
} 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View theView = inflater.inflate(R.layout.fragment_events_past, container, true); 
    String[] fakeData = {"Donald Trump is running for president","Twins trade for Clayton Kershaw", 
    "Derek Banas's Android Tutorial Series Helped Me Make This","This is some more fake news"}; 
    ListView listView = (ListView) theView.findViewById(R.id.fragment_events_past_list_view); 
    ListAdapter adapter = new MyAdapter(getContext(),fakeData); 
    listView.setAdapter(adapter); 
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { 

     } 
    }); 
    // Inflate the layout for this fragment 
    return theView; 
} 

} 

下面是XML文件 fragment_events_past.xml

<FrameLayout 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" 
tools:context=".EventsPast"> 

<!-- TODO: Update blank fragment layout --> 

<ListView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/fragment_events_past_list_view" 
    android:layout_gravity="left|top" /> 
</FrameLayout> 

events_past_list_item.xml

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

<ImageView 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="15dp" 
    android:id="@+id/image_view" 
    android:src="@drawable/icon_events"/> 


<TextView 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:textSize="16sp" 
    android:id="@+id/text_view" 
    android:gravity="center_vertical"/> 
</LinearLayout> 

錯誤消息

07-30 16:38:14.888 22018-22018/com.lucasmikesoftware.messaround d /錯誤:ERR:堆棧= java.lang.StackOverflowError的:堆棧大小8MB 在機器人。 view.View.invalidateInternal(View.java:11749) at android.view.View.invalidate(View.java:11711) at android.view.View.invalidateDrawable(View.java:15845) at android.graphics。 drawable.Drawable.invalidateSelf(Drawable.java:367) 在android.graphics.drawable.RippleDrawable.jumpToCurrentState(RippleDrawable.java:221) 在android.widget.AbsListView.jumpDrawablesToCurrentState(AbsListView.java:2974) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:224) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在機器人。 view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5 848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGrou p.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup中。的java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup中。的java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java: 5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) at android.view.ViewGroup.jumpDrawablesToCurrentState(Vi ewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup中。的java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java: 5848) at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) at android.view.ViewGroup.jumpDrawablesToCurrent國家(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState( ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup中。 java:5848) at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) at android.view.ViewGroup.jumpDrawablesT oCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5848) 在android.view.ViewGroup.jumpDrawablesToCurrentState( (3024B)AllocSpace對象,1(1)(1)(3)(3)(3) (22MB)LOS對象,14%免費,92MB/108MB,暫停1.953ms總計215.717ms 07-30 16:38:14.908 22018-22018/com.lucasmikesoftware.messaround E/JavaBinder:!!!失敗的粘合劑交易!!! 07-30 16:38:14.908 22018-22018/com.lucasmikesoftware.messaround D /錯誤:ERR:全部字節被寫入:19877752 07-30 16:38:14.908 22018-22018/com.lucasmikesoftware.messaround E/AndroidRuntime :錯誤報告崩潰 android.os.TransactionTooLargeException 在android.os.BinderProxy.transactNative(本機方法) 在android.os.BinderProxy.transact(Binder.java:504) 在android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative .java:4179) at com.android.internal.os.RuntimeInit $ UncaughtHandler.uncaughtException(RuntimeInit.java:118) at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) at java.lang.ThreadGroup.uncaughtException(ThreadGroup。java:690) 07-30 16:38:14.908 22018-22018/com.lucasmikesoftware.messaround D/Process:killProcess,pid = 22018 07-30 16:38:14.918 22018-22018/com.lucasmikesoftware.messaround D /過程:com.android.internal.os.RuntimeInit $ UncaughtHandler.uncaughtException:138 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690

+0

請添加堆棧跟蹤,以便我們看到異常的原因 –

回答

0

EventsPast.onCreateView與線

充氣佈局
View theView = inflater.inflate(R.layout.fragment_events_past, container, true); 

第三個參數boolean attachToRoot應該是false。您不應該將新膨脹的佈局附加到根目錄(在此情況下爲container),因爲Fragment旨在按照onCreateView的要求返回theView後執行此操作。

它能夠讓您的代碼與此修改一起工作。