我只是编程的初学者,我需要一个汽车列表视图。在大多数情况下它可以工作,但是当我在列表底部滚动时,它会崩溃。
这是Java类的代码:
package com.carschoolingpromo.scires.carschooling;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class CarbonEmissions extends AppCompatActivity {
int [] IMAGES = {R.drawable.chevycruze, R.drawable.fordeverest, R.drawable.fordfiesta, R.drawable.hondacitysedan, R.drawable.hondajazz, R.drawable.hyundaiaccent, R.drawable.isuzudmax, R.drawable.kiapicanto,
R.drawable.mitsumirage, R.drawable.mitsusuvmontero, R.drawable.nissancerifo, R.drawable.subaruxv, R.drawable.suzukivitara, R.drawable.toyotafortuner,
R.drawable.toyotainnova5, R.drawable.toyotainnova6, R.drawable.toyotarevo};
String [] MAKE = {"Chevrolet", "Ford", "Ford", "Honda", "Honda", "Hyundai", "Isuzu", "Kia", "Mitsubishi", "Mitsubishi", "Nissan", "Subaru", "Suzuki", "Toyota",
"Totoya","Totoya", "Totoya", "Totoya"};
String [] MODEL = {"Cruze", "Everest", "Fiesta", "City", "Jazz", "Accent", "D Max", "Picanto", "Mirage", "Montero", "Cefiro", "XV", "Vitara", "Fortuner", "Innova", "Innova", "Revo"};
String [] YEAR = {"2012", "2016", "2013", "2018", "2009", "2010", "2014", "2015", "2014", "2010", "1997", "2015", "2012", "2015", "2016", "2004"};
String [] FUEL = {"Gasoline", "Diesel", "Unleaded", "Gasoline", "Gasoline", "Diesel", "Diesel", "Diesel", "Gas / Unleaded", "Diesel", "Gasoline", "Gasoline", "Gasoline", "Diesel", "Diesel", "Gasoline"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_carbon_emissions);
ListView listView=(ListView)findViewById(R.id.ListView);
CustomAdapter customAdapter=new CustomAdapter();
listView.setAdapter(customAdapter);
}
class CustomAdapter extends BaseAdapter{
@Override
public int getCount() {
return IMAGES.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = getLayoutInflater().inflate(R.layout.custom,null);
ImageView imageView = (ImageView)view.findViewById(R.id.imageView);
TextView textView_make=(TextView)view.findViewById(R.id.textView5_make);
TextView textView_model=(TextView)view.findViewById(R.id.textView6_model);
TextView textView_year=(TextView)view.findViewById(R.id.textView7_year);
TextView textView_fuel=(TextView)view.findViewById(R.id.textView8_fuel);
imageView.setImageResource(IMAGES[i]);
textView_make.setText(MAKE[i]);
textView_model.setText(MODEL[i]);
textView_year.setText(YEAR[i]);
textView_fuel.setText(FUEL[i]);
return view;
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.carschoolingpromo.scires.carschooling.CarbonEmissions"
android:background="@drawable/green">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ListView"></ListView>
</RelativeLayout>
CUSTOM XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="16dp"
android:layout_marginTop="88dp"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:textSize = "22sp"
android:id="@+id/textView5_make"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView"
android:layout_toEndOf="@+id/imageView"
android:text="TextView" />
<TextView
android:textSize = "22sp"
android:id="@+id/textView6_model"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView5_make"
android:layout_marginTop="15dp"
android:layout_toEndOf="@+id/imageView"
android:text="TextView" />
<TextView
android:textSize = "22sp"
android:id="@+id/textView7_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView5"
android:layout_alignBottom="@+id/textView5_make"
android:layout_marginStart="49dp"
android:layout_toEndOf="@+id/textView5_make"
android:text="TextView" />
<TextView
android:textSize = "22sp"
android:id="@+id/textView8_fuel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView6_model"
android:layout_alignBottom="@+id/textView6_model"
android:layout_alignStart="@+id/textView7_year"
android:text="TextView" />
</RelativeLayout>
错误日志
02-06 18:52:03.054 19152-19152/? E/Zygote: v2
02-06 18:52:03.055 19152-19152/? I/libpersona: KNOX_SDCARD checking this for 10257
02-06 18:52:03.055 19152-19152/? I/libpersona: KNOX_SDCARD not a persona
02-06 18:52:03.057 19152-19152/? E/Zygote: accessInfo : 0
02-06 18:52:03.058 19152-19152/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.0_0005, [-1 -1 -1 -1 0 1]
02-06 18:52:03.060 19152-19152/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.carschoolingpromo.scires.carschooling
02-06 18:52:03.065 19152-19152/? I/art: Late-enabling -Xcheck:jni
02-06 18:52:03.093 19152-19152/? D/TimaKeyStoreProvider: TimaSignature is unavailable
02-06 18:52:03.094 19152-19152/? D/ActivityThread: Added TimaKeyStore provider
02-06 18:52:03.110 19152-19159/? I/art: Debugger is no longer active
02-06 18:52:03.110 19152-19159/? I/art: Starting a blocking GC Instrumentation
02-06 18:52:03.303 19152-19152/? W/System: ClassLoader referenced unknown path: /data/app/com.carschoolingpromo.scires.carschooling-1/lib/arm64
02-06 18:52:03.319 19152-19152/? D/ContextRelationMgrBrdg: loadKlass() : caller=com.samsung.android.bridge.multiscreen.common.ContextRelationManagerBridge.<clinit>:28 android.app.LoadedApk.makeApplication:840
02-06 18:52:03.329 19152-19152/? I/InstantRun: starting instant run server: is main process
02-06 18:52:03.407 19152-19152/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-06 18:52:03.499 19152-19152/? D/TextView: setTypeface with style : 0
02-06 18:52:03.500 19152-19152/? D/TextView: setTypeface with style : 0
02-06 18:52:03.776 19152-19152/? D/InputTransport: Input channel constructed: fd=73
02-06 18:52:03.776 19152-19152/? D/ViewRootImpl@8b1a874[WelcomeScreen]: setView = DecorView@2b0419d[WelcomeScreen] touchMode=true
02-06 18:52:03.820 19152-19170/? I/OpenGLRenderer: Initialized EGL, version 1.4
02-06 18:52:03.820 19152-19170/? D/OpenGLRenderer: Swap behavior 1
02-06 18:52:03.829 19152-19170/? D/libGLESv1: STS_GLApi : DTS is not allowed for Package : com.carschoolingpromo.scires.carschooling
02-06 18:52:03.833 19152-19170/? D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1080x1920]-format:1
02-06 18:52:03.854 19152-19152/? W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
02-06 18:52:03.860 19152-19152/? D/ViewRootImpl@8b1a874[WelcomeScreen]: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
02-06 18:52:03.860 19152-19152/? D/ViewRootImpl@8b1a874[WelcomeScreen]: MSG_WINDOW_FOCUS_CHANGED 1
02-06 18:52:03.860 19152-19152/? V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@577f612 nm : com.carschoolingpromo.scires.carschooling ic=null
02-06 18:52:03.860 19152-19152/? I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
02-06 18:52:03.867 19152-19165/? D/InputTransport: Input channel constructed: fd=80
02-06 18:52:04.255 19152-19152/com.carschoolingpromo.scires.carschooling V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@4f971e3 nm : com.carschoolingpromo.scires.carschooling ic=null
02-06 18:52:05.378 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@8b1a874[WelcomeScreen]: ViewPostImeInputStage processPointer 0
02-06 18:52:05.380 19152-19152/com.carschoolingpromo.scires.carschooling W/System: ClassLoader referenced unknown path: /system/framework/QPerformance.jar
02-06 18:52:05.383 19152-19152/com.carschoolingpromo.scires.carschooling E/BoostFramework: BoostFramework() : Exception_1 = java.lang.ClassNotFoundException: Didn't find class "com.qualcomm.qti.Performance" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
02-06 18:52:05.383 19152-19152/com.carschoolingpromo.scires.carschooling V/BoostFramework: BoostFramework() : mPerf = null
02-06 18:52:05.486 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@8b1a874[WelcomeScreen]: ViewPostImeInputStage processPointer 1
02-06 18:52:05.517 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@8b1a874[WelcomeScreen]: MSG_WINDOW_FOCUS_CHANGED 0
02-06 18:52:05.600 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:05.601 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:05.831 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:05.843 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:05.851 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:05.858 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:05.863 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:05.887 19152-19152/com.carschoolingpromo.scires.carschooling D/InputTransport: Input channel constructed: fd=84
02-06 18:52:05.887 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@67d193[MainMenu]: setView = DecorView@8c135d0[MainMenu] touchMode=true
02-06 18:52:05.947 19152-19170/com.carschoolingpromo.scires.carschooling D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1080x1920]-format:1
02-06 18:52:06.249 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@67d193[MainMenu]: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
02-06 18:52:06.249 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@67d193[MainMenu]: MSG_WINDOW_FOCUS_CHANGED 1
02-06 18:52:06.251 19152-19152/com.carschoolingpromo.scires.carschooling V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@7cbdefc nm : com.carschoolingpromo.scires.carschooling ic=null
02-06 18:52:06.251 19152-19152/com.carschoolingpromo.scires.carschooling I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
02-06 18:52:06.268 19152-19152/com.carschoolingpromo.scires.carschooling D/InputTransport: Input channel constructed: fd=89
02-06 18:52:06.268 19152-19152/com.carschoolingpromo.scires.carschooling D/InputTransport: Input channel destroyed: fd=80
02-06 18:52:07.151 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@67d193[MainMenu]: ViewPostImeInputStage processPointer 0
02-06 18:52:07.246 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@67d193[MainMenu]: ViewPostImeInputStage processPointer 1
02-06 18:52:07.292 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@67d193[MainMenu]: MSG_WINDOW_FOCUS_CHANGED 0
02-06 18:52:07.367 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.368 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.378 19152-19152/com.carschoolingpromo.scires.carschooling D/AbsListView: Get MotionRecognitionManager
02-06 18:52:07.383 19152-19152/com.carschoolingpromo.scires.carschooling D/MotionRecognitionManager: mSContextService = com.samsung.android.hardware.context.ISemContextService$Stub$Proxy@f76e218
02-06 18:52:07.385 19152-19152/com.carschoolingpromo.scires.carschooling D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@511c471
02-06 18:52:07.385 19152-19152/com.carschoolingpromo.scires.carschooling D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@511c471
02-06 18:52:07.403 19152-19152/com.carschoolingpromo.scires.carschooling D/InputTransport: Input channel constructed: fd=80
02-06 18:52:07.404 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@2d14256[CarbonEmissions]: setView = DecorView@9d3a2d7[CarbonEmissions] touchMode=true
02-06 18:52:07.443 19152-19170/com.carschoolingpromo.scires.carschooling D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1080x1920]-format:1
02-06 18:52:07.454 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.459 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.462 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.465 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.499 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.501 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.503 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.505 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.538 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.539 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.541 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.543 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.574 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.580 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.582 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.586 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.628 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.631 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.634 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.636 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.668 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.670 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.671 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.673 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:07.700 19152-19152/com.carschoolingpromo.scires.carschooling D/AbsListView: onsize change
02-06 18:52:07.818 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@2d14256[CarbonEmissions]: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
02-06 18:52:07.818 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@2d14256[CarbonEmissions]: MSG_WINDOW_FOCUS_CHANGED 1
02-06 18:52:07.822 19152-19152/com.carschoolingpromo.scires.carschooling V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@acf8f8d nm : com.carschoolingpromo.scires.carschooling ic=null
02-06 18:52:07.822 19152-19152/com.carschoolingpromo.scires.carschooling I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
02-06 18:52:07.836 19152-19152/com.carschoolingpromo.scires.carschooling D/InputTransport: Input channel constructed: fd=91
02-06 18:52:07.836 19152-19152/com.carschoolingpromo.scires.carschooling D/InputTransport: Input channel destroyed: fd=89
02-06 18:52:09.229 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@2d14256[CarbonEmissions]: ViewPostImeInputStage processPointer 0
02-06 18:52:09.331 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.339 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.347 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.355 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.415 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.422 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.426 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.430 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.470 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.474 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.478 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.481 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.519 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.522 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.525 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.528 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.561 19152-19152/com.carschoolingpromo.scires.carschooling D/ViewRootImpl@2d14256[CarbonEmissions]: ViewPostImeInputStage processPointer 1
02-06 18:52:09.634 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.638 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.643 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.648 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.701 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.705 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.709 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.713 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.759 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.761 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.763 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.764 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.791 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.792 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.793 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.795 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.840 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.841 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.842 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.843 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.893 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.895 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.899 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.902 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.977 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.980 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.983 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:09.986 19152-19152/com.carschoolingpromo.scires.carschooling D/TextView: setTypeface with style : 0
02-06 18:52:10.010 19152-19152/com.carschoolingpromo.scires.carschooling D/AndroidRuntime: Shutting down VM
02-06 18:52:10.011 19152-19152/com.carschoolingpromo.scires.carschooling E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.carschoolingpromo.scires.carschooling, PID: 19152
java.lang.ArrayIndexOutOfBoundsException: length=16; index=16
at com.carschoolingpromo.scires.carschooling.CarbonEmissions$CustomAdapter.getView(CarbonEmissions.java:61)
at android.widget.AbsListView.obtainView(AbsListView.java:3229)
at android.widget.ListView.makeAndAddView(ListView.java:2147)
at android.widget.ListView.fillDown(ListView.java:767)
at android.widget.ListView.fillGap(ListView.java:731)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:8378)
at android.widget.ListView.trackMotionScroll(ListView.java:2065)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:7805)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:635)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
答案 0 :(得分:0)
在:
public View getView(int i, View view, ViewGroup viewGroup) {
view = getLayoutInflater().inflate(R.layout.custom,null);
你应该在使用之前检查view == null。可能没有显示的视图(因为您超出列表视图的末尾)。
if(view==null)
{
return null;
}
答案 1 :(得分:0)
数组索引超出绑定异常表示您正在尝试访问元素16,该元素是数组中仅包含16个元素的第17个元素。
因此,您可以像这样修改getcount()
public int getCount() {
return Year.length;
}
或者可以如@Neil
所示