Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPager "TransactionTooLargeException" on test ViewPager

I'm implementing ViewPager for the first time and I'm facing some issue because I get following error:

06-20 10:40:51.366 11377-11377/com.example.ruelas.elite E/AndroidRuntime: Error reporting crash
                                                                      android.os.TransactionTooLargeException: data parcel size 26485896 bytes
                                                                          at android.os.BinderProxy.transactNative(Native Method)
                                                                          at android.os.BinderProxy.transact(Binder.java:503)
                                                                          at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4425)
                                                                          at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:90)
                                                                          at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                                          at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

Im not doing anything fancy with ViewPager but I'm not able to make it work, this is the Activity thats running it:

package com.example.ruelas.elite;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

public class setup extends AppCompatActivity {
ViewPager vpSetup;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup);
    vpSetup = (ViewPager)findViewById(R.id.vpSetup);
    vpSetup.setAdapter(new adapterSetup(getSupportFragmentManager()));
}
}

The adapterSetup Class:

package com.example.ruelas.elite;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

public class adapterSetup extends FragmentPagerAdapter {
String [] titulos = new String[]{"Modalidad", "Temas"};
public adapterSetup(FragmentManager fm) {
    super(fm);
}
@Override
public Fragment getItem(int position) {
    switch (position){
        case 0:
            Log.d("case0","case0");
            return new fragmentModalidad();
        case 1:
            return new fragmentTemas();
        default:
            return null;
    }
}
@Override
public int getCount() {
    return titulos.length;
}
@Override
public CharSequence getPageTitle(int position) {
    return titulos[position];
}
}

My gradle since I think it may have something to do with this:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.example.ruelas.elite"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.0.0'
}

One of the fragments (they are just XMLS with a Large Text in them:

package com.example.ruelas.elite;

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Ruelas on 20/06/2016.
 */
public class fragmentModalidad extends Fragment{
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragmentmodalidad, container, false);
    }
}

Thank you in advance, feel free to ask if I missed any necessary information.

like image 312
LuisE Avatar asked Jun 20 '16 17:06

LuisE


1 Answers

My bad guys, the other class inflater was not calling the correct constructor, it was:

return inflater.inflate(R.layout.fragmentmodalidad, container);

When:

return inflater.inflate(R.layout.fragmentmodalidad, container, false);

was needed

like image 172
LuisE Avatar answered Oct 16 '22 04:10

LuisE