gpt4 book ai didi

android - ViewPager "TransactionTooLargeException"测试 ViewPager

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:28 31 4
gpt4 key购买 nike

我是第一次实现 ViewPager,我遇到了一些问题,因为我收到以下错误:

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)

我没有对 ViewPager 做任何花哨的事情,但我无法让它工作,这是运行它的 Activity:

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()));
}
}

adapterSetup 类:

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];
}
}

我的 gradle 因为我认为它可能与此有关:

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'
}

其中一个 fragment (它们只是带有大文本的 XMLS:

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);
}
}

在此先感谢您,如果我遗漏了任何必要的信息,请随时询问。

最佳答案

我的坏人,另一个类 inflater 没有调用正确的构造函数,它是:

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

时间:

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

需要

关于android - ViewPager "TransactionTooLargeException"测试 ViewPager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37928394/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com