java.lang.Class Cast Exception: android.widget.HeaderViewListAdapter

本文介绍了解决在ListView上添加HeaderView时遇到的ClassCastException异常的方法。通过将原始Adapter包装为HeaderViewListAdapter,并从HeaderViewListAdapter中获取被包装的Adapter,可以避免类型转换异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题背景: 最近写一个项目,根据屏幕左侧的字母查找好友,在网上找了个Demo,现在我想在显示好友的ListView上面增加一个HeaderView,运行的时候报了这个错误。

下面是Demo中的一个自定义View的代码:

public class SideBar extends View {
private char[] mL;
private SectionIndexer mSectionIndexter = null;
private ListView mList;
private TextView mDialogText;
private final int mM_nItemHeight = 15;

public SideBar(Context context) {
super(context);
init();
}

public SideBar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public SideBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

private void init() {
mL = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z' };
}

public void setListView(ListView listView) {
mList = listView;
HeaderViewListAdapter ha = (HeaderViewListAdapter) listView.getAdapter();
mSectionIndexter = (SectionIndexer) ha.getWrappedAdapter();
//mSectionIndexter = (SectionIndexer) listView.getAdapter();
}

public void setTextView(TextView mDialogText) {
this.mDialogText = mDialogText;
}

public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int i = (int) event.getY();
int idx = i / mM_nItemHeight;
if (idx >= mL.length) {
idx = mL.length - 1;
} else if (idx < 0) {
idx = 0;
}
if (event.getAction() == MotionEvent.ACTION_DOWN
|| event.getAction() == MotionEvent.ACTION_MOVE) {
mDialogText.setVisibility(View.VISIBLE);
mDialogText.setText("" + mL[idx]);
if (mSectionIndexter == null) {
mSectionIndexter = (SectionIndexer) mList.getAdapter();
}
int position = mSectionIndexter.getPositionForSection(mL[idx]);
if (position == -1) {
return true;
}
mList.setSelection(position);
} else {
mDialogText.setVisibility(View.INVISIBLE);
}
return true;
}

protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(0xff595c61);
paint.setTextSize(12);
paint.setTextAlign(Paint.Align.CENTER);
float widthCenter = getMeasuredWidth() / 2;
for (int i = 0; i < mL.length; i++) {
canvas.drawText(String.valueOf(mL[i]), widthCenter, mM_nItemHeight
+ (i * mM_nItemHeight), paint);
}
super.onDraw(canvas);
}
}

解决方法:

ListView增加HeaderView之后,将原来的Adapter包装成HeaderViewListAdapter,看看HeaderViewListAdapter的文档说明:

ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects.

This is intended as a base class; you will probably not need to use this class directly in your own code.

HeaderViewListAdapter有个方法getWrappedAdapter,该方法能返回被包装的HeaderViewListAdapter的ListAdapter。

到了这里就明白为什么会报ClassCastException异常了。因为ListView的getAdapter方法返回的是HeaderViewListAdapter的实例,而将其转换成BaseAdapter的子类的实例,肯定是不对的。

下面是我给显示好友的ListView设置HeaderView和Adapter的代码:

// 这里要注意,给ListView增加HeaderView和Adapter顺序,不然会报错。

LinearLayout headerView = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.weibo_friends_listheader, null);
mFriendsContact.addHeaderView(headerView);

mFriendsContact.setAdapter(new FriendListViewAdapter(this, mNicks));
mIndexBar.setListView(mFriendsContact);

注意上面SideBar这个类中红色标记方法内的代码:

public void setListView(ListView listView) {
mList = listView;

//更改后的,我在获得ListView的Adapter之前进行了一下转换
HeaderViewListAdapter ha = (HeaderViewListAdapter) listView.getAdapter();
mSectionIndexter = (SectionIndexer) ha.getWrappedAdapter();

//更改前的
//mSectionIndexter = (SectionIndexer) listView.getAdapter();
}

可以参考这篇文章: http://hi.baidu.com/su350380433/item/3e70f16022b0471b7ddeccd8
2025-07-28 11:10:19.676 5188-5188 TransactionExecutor com.example.myapplication E Failed to execute the transaction: tId:-489014647 ClientTransaction{ tId:-489014647 transactionItems=[ tId:-489014647 LaunchActivityItem{activityToken=android.os.BinderProxy@b507644,intent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.myapplication/.MainActivity },ident=210528473,info=ActivityInfo{421fde2 com.example.myapplication.MainActivity},curConfig={1.0 310mcc260mnc [en_US] ldltr sw411dp w411dp h842dp 420dpi nrml long port finger qwerty/v/v dpad/v winConfig={ mBounds=Rect(0, 0 - 1080, 2400) mAppBounds=Rect(0, 128 - 1080, 2337) mMaxBounds=Rect(0, 0 - 1080, 2400) mDisplayRotation=ROTATION_0 mWindowingMode=fullscreen mActivityType=undefined mAlwaysOnTop=undefined mRotation=ROTATION_0} as.3 s.109 fontWeightAdjustment=0},overrideConfig={1.0 310mcc260mnc [en_US] ldltr sw411dp w411dp h842dp 420dpi nrml long port finger qwerty/v/v dpad/v winConfig={ mBounds=Rect(0, 0 - 1080, 2400) mAppBounds=Rect(0, 128 - 1080, 2337) mMaxBounds=Rect(0, 0 - 1080, 2400) mDisplayRotation=ROTATION_0 mWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} as.3 s.3 fontWeightAdjustment=0},deviceId=0,referrer=com.android.shell,procState=2,state=null,persistentState=null,pendingResults=null,pendingNewIntents=null,sceneTransitionInfo=null,profilerInfo=null,assistToken=android.os.BinderProxy@4a532d7,shareableActivityToken=android.os.BinderProxy@91e57c4,activityWindowInfo=ActivityWindowInfo{isEmbedded=false, taskBounds=Rect(0, 0 - 1080, 2400), taskFragmentBounds=Rect(0, 0 - 1080, 2400)}} tId:-489014647 ResumeActivityItem{mActivityToken=android.os.BinderProxy@b507644,procState=-1,updateProcState=false,isForward=true,shouldSendCompatFakeFocus=false} tId:-489014647 Target activity: com.example.myapplication.MainActivity tId:-489014647 ] tId:-489014647 } 2025-07-28 11:10:19.677 5188-5188 AndroidRuntime com.example.myapplication D Shutting down VM 2025-07-28 11:10:19.678 5188-5188 AndroidRuntime com.example.myapplication E FATAL EXCEPTION: main Process: com.example.myapplication, PID: 5188 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.ClassCastException: com.google.android.material.textfield.MaterialAutoCompleteTextView cannot be cast to android.widget.Spinner at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4047) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4234) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:112) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2635) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8699) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886) Caused by: java.lang.ClassCastException: com.google.android.material.textfield.MaterialAutoCompleteTextView cannot be cast to android.widget.Spinner at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:21) at android.app.Activity.performCreate(Activity.java:8980) at android.app.Activity.performCreate(Activity.java:8958) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1526) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4029) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4234)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:112)  at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174)  at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2635)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loopOnce(Looper.java:232)  at android.os.Looper.loop(Looper.java:317)  at android.app.ActivityThread.main(ActivityThread.java:8699)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)  2025-07-28 11:10:19.776 5188-5193 e.myapplication com.example.myapplication I Compiler allocated 4219KB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
最新发布
07-29
07-21 16:57:24.053 18140 18140 I ls_test : removeUsbDevice 07-21 16:57:24.053 18140 18140 I MicHelper: mode:3 07-21 16:57:24.054 4919 4919 I HwCarCommonSDK:VehicleConfigurationWord: Get cfg val by dynamic_projection_lamp 07-21 16:57:24.054 4919 4919 E HwCarCommonSDK:VehicleConfigurationWord: Don't support : dynamic_projection_lamp, please check configuration xml. 07-21 16:57:24.054 4919 4919 I HwCarCommonSDK:VehicleConfigurationWord: Get cfg val by dynamic_lamp_projection_type 07-21 16:57:24.054 4919 4919 E HwCarCommonSDK:VehicleConfigurationWord: Don't support : dynamic_lamp_projection_type, please check configuration xml. 07-21 16:57:24.054 4919 4919 E HwCarCommonSDK:BaseCfg: wordValue is invalid, usually caused by empty word info map. 07-21 16:57:24.054 614 614 I android.system.suspend@1.0-service: decSuspendCounter kname=native_ApmAudio --mSuspendCounter= 4 07-21 16:57:24.054 614 614 I android.system.suspend@1.0-service: incSuspendCounter kname=native_ApmOutput ++mSuspendCounter= 5 07-21 16:57:24.054 1211 21300 W APM::AudioInputDescriptor: close client with port ID 510 still active on input 509 07-21 16:57:24.054 1211 21300 I APM::AudioInputDescriptor: setClientActive(uid:1000, session:369, state:2, silenced:0 active:0) 07-21 16:57:24.054 1211 21300 I APM::AudioInputDescriptor: stop, input handle 686, profile name: mixport_input_bus_voice_upload, curActiveCount: 0 07-21 16:57:24.054 1211 21300 I AudioFlinger: closeInput() 686 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: Config is relaunching invisible activity ActivityRecord{cb10d7a u10 com.huawei.hmsauto.cast.car/.projection.view.ProjectionActivity t1000112}, changes=0x30 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: relaunch this:ActivityRecord{cb10d7a u10 com.huawei.hmsauto.cast.car/.projection.view.ProjectionActivity t1000112}, andResume:true 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: java.lang.Exception 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.ActivityRecord.relaunchActivityLocked(ActivityRecord.java:11708) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.ActivityRecord.ensureActivityConfiguration(ActivityRecord.java:11456) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.ActivityRecord.ensureActivityConfiguration(ActivityRecord.java:11215) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.ActivityTaskManagerService.ensureConfigAndVisibilityAfterUpdate(ActivityTaskManagerService.java:6146) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.DisplayContent.updateDisplayOverrideConfigurationLocked(DisplayContent.java:7543) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.DisplayContent.updateDisplayOverrideConfigurationLocked(DisplayContent.java:7504) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.DisplayContent.sendNewConfiguration(DisplayContent.java:1903) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.InputManagerCallback$$ExternalSyntheticLambda2.accept(Unknown Source:2) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.RootWindowContainer.forAllDisplays(RootWindowContainer.java:1671) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.wm.InputManagerCallback.notifyConfigurationChanged(InputManagerCallback.java:142) 07-21 16:57:24.055 2528 2773 I ActivityTaskManager: at com.android.server.input.InputManagerService.notifyConfigurationChanged(InputManagerService.java:3487) 07-21 16:57:24.055 614 614 I android.system.suspend@1.0-service: decSuspendCounter kname=native_ApmOutput --mSuspendCounter= 4 07-21 16:57:24.055 2528 2773 E ActivityTaskManager: ensureVisibilityAndConfig starting:ActivityRecord{cb10d7a u10 com.huawei.hmsauto.cast.car/.projection.view.ProjectionActivity t1000112}, kept:false 07-21 16:57:24.055 25188 25202 I LifecycleTransaction: activityCallbacks ActivityRelaunchItem{pendingResults=null,pendingNewIntents=null,configChanges=48,config={mGlobalConfig={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw540dp w960dp h444dp 320dpi nrml long hdr widecg land car finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1920, 1080) mAppBounds=Rect(0, 0 - 1920, 984) mMaxBounds=Rect(0, 0 - 1920, 1080) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=undefined mAlwaysOnTop=undefined mRotation=ROTATION_0 mPopOverMode=0} hwt:1 suim:1 extflag:8 s.3972 fontWeightAdjustment=0} mOverrideConfig={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw540dp w960dp h444dp 320dpi nrml long hdr widecg land car finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1920, 1080) mAppBounds=Rect(0, 0 - 1920, 984) mMaxBounds=Rect(0, 0 - 1920, 1080) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0 mPopOverMode=0} hwt:1 suim:1 userId:-10000 extflag:8 s.2 fontWeightAdjustment=0}},preserveWindowfalse} 07-21 16:57:24.055 25188 25202 I LifecycleTransaction: lifecycleStateRequest ResumeActivityItem{procState=-1,updateProcState=false,isForward=false} 07-21 16:57:24.056 11029 14482 I LifecycleTransaction: activityCallbacks ActivityConfigurationChange{config={0.0 ?mcc?mnc ?localeList ?layoutDir sw2147483647dp w960dp h264dp ?density nrml hdr widecg land ?uimode ?night -touch qwerty/v/v -nav/h winConfig={ mBounds=Rect(0, 0 - 1920, 720) mAppBounds=Rect(0, 0 - 1920, 624) mMaxBounds=Rect(0, 0 - 1920, 720) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0 mPopOverMode=0} userId:-10000 s.56 ?fontWeightAdjustment}} 07-21 16:57:24.056 1211 21300 I AudioFlinger: ThreadBase::exit 07-21 16:57:24.056 25188 25188 I SurfaceView: ViewUI 257196412 Changes: creating=false format=false size=false visible=true view_current=true mRequestedVisible=false alpha=false hint=false Alpha=false win=false win_current=true win_last=true position=false layout=false left=false top=false, Size: mReqW=498 mReqH=1080 w=498 h=1080 07-21 16:57:24.056 25188 25188 I SurfaceView: ViewUI 257196412 updateBoundsLayerCornerRadius isSetBefore=false isSet=false 07-21 16:57:24.056 25188 25188 I SurfaceView: ViewUI 257196412 surfaceDestroyed 分析为何ProjectionActivity relaunch了
07-24
分析以下代码的报错信息:------------------------- PROCESS STARTED (7432) for package com.example.myapplication ---------------------------- 2025-07-09 13:27:09.041 7432-7432 e.myapplicatio com.example.myapplication W ClassLoaderContext classpath size mismatch. expected=0, found=1 (PCL[] | PCL[/data/data/com.example.myapplication/code_cache/.overlay/base.apk/classes3.dex*4250602868]) 2025-07-09 13:27:09.042 7432-7432 e.myapplicatio com.example.myapplication W Found duplicate classes, falling back to extracting from APK : /data/app/~~dh0o8WK_fXecSV_JJz78RQ==/com.example.myapplication-RE5zX8NpQzXhviy1xPMobA==/base.apk 2025-07-09 13:27:09.042 7432-7432 e.myapplicatio com.example.myapplication W NOTE: This wastes RAM and hurts startup performance. 2025-07-09 13:27:09.042 7432-7432 e.myapplicatio com.example.myapplication W Found duplicated class when checking oat files: 'Lcom/example/myapplication/ListActivity$1;' in /data/data/com.example.myapplication/code_cache/.overlay/base.apk/classes3.dex and /data/app/~~dh0o8WK_fXecSV_JJz78RQ==/com.example.myapplication-RE5zX8NpQzXhviy1xPMobA==/base.apk!classes3.dex 2025-07-09 13:27:09.172 7432-7432 NetworkSecurityConfig com.example.myapplication D No Network Security Config specified, using platform default 2025-07-09 13:27:09.173 7432-7432 NetworkSecurityConfig com.example.myapplication D No Network Security Config specified, using platform default 2025-07-09 13:27:09.201 7432-7456 libEGL com.example.myapplication D loaded /vendor/lib/egl/libEGL_emulation.so 2025-07-09 13:27:09.202 7432-7456 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2025-07-09 13:27:09.204 7432-7456 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv2_emulation.so 2025-07-09 13:27:09.246 7432-7432 AppCompatDelegate com.example.myapplication D Checking for metadata for AppLocalesMetadataHolderService : Service not found 2025-07-09 13:27:09.305 7432-7432 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2025-07-09 13:27:09.305 7432-7432 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2025-07-09 13:27:09.397 7432-7454 HostConnection com.example.myapplication D HostConnection::get() New Host Connection established 0xe9a68250, tid 7454 2025-07-09 13:27:09.403 7432-7454 HostConnection com.example.myapplication D HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 2025-07-09 13:27:09.404 7432-7454 OpenGLRenderer com.example.myapplication W Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2025-07-09 13:27:09.411 7432-7454 EGL_emulation com.example.myapplication D eglCreateContext: 0xe9a68170: maj 2 min 0 rcv 2 2025-07-09 13:27:09.414 7432-7454 EGL_emulation com.example.myapplication D eglMakeCurrent: 0xe9a68170: ver 2 0 (tinfo 0xe9db64d0) (first time) 2025-07-09 13:27:09.438 7432-7454 Gralloc4 com.example.myapplication I mapper 4.x is not supported 2025-07-09 13:27:09.439 7432-7454 HostConnection com.example.myapplication D createUnique: call 2025-07-09 13:27:09.439 7432-7454 HostConnection com.example.myapplication D HostConnection::get() New Host Connection established 0xe9a6acc0, tid 7454 2025-07-09 13:27:09.467 7432-7454 HostConnection com.example.myapplication D HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 2025-07-09 13:27:10.478 7432-7432 AndroidRuntime com.example.myapplication D Shutting down VM 2025-07-09 13:27:10.479 7432-7432 AndroidRuntime com.example.myapplication E FATAL EXCEPTION: main Process: com.example.myapplication, PID: 7432 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:1068) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:409) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109) at android.app.Dialog.show(Dialog.java:340) at android.app.AlertDialog$Builder.show(AlertDialog.java:1131) at com.example.myapplication.MyBaseAdapter$1.onClick(MyBaseAdapter.java:55) at android.view.View.performClick(View.java:7448) at android.view.View.performClickInternal(View.java:7425) at android.view.View.access$3600(View.java:810) at android.view.View$PerformClick.run(View.java:28305) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 2025-07-09 13:27:10.509 7432-7432 Process com.example.myapplication I Sending signal. PID: 7432 SIG: 9 ---------------------------- PROCESS ENDED (7432) for package com.example.myapplication ----------------------------
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值