我是第一次实现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()));
}
}
适配器设置类:
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'
}
其中一个片段(它们只是带有大文本的XML文件):
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);
}
}
提前感谢您,如有遗漏必要信息,请随时提出。