android null强转类型,android-kotlin.TypeCastException:无法将null强制转换为非null类型的kotlin.collections.Map...

我一直在寻找可以广泛帮助我的代码的答案,但是我发现的解决方案对我不起作用.

我收到以下错误:

kotlin.TypeCastException: null cannot be cast to non-null

type kotlin.collections.Map

FATAL EXCEPTION: main

Process: com.meetHitch.HitchApp, PID: 4021

kotlin.TypeCastException: null cannot be cast to non-null

type kotlin.collections.Map

at ... helpers.RestAPIKt$getUserProfile$1 ...

at com.google.android.gms.tasks.zzj.run(Unknown Source)

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 ...

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.ZygoteInit$Method...

at com.android.internal.os.ZygoteInit.main

我的代码如下:

private val TAG: String

get() = "RestAPI"

private val fUser: FirebaseUser?

get() = FirebaseAuth.getInstance().currentUser

private val uid: String?

get() = fUser?.uid

private val baseDoc: DocumentReference

get() = FirebaseFirestore.getInstance().

collection("users").document(uid!!)

private val leadsDoc: DocumentReference

get() {

appUser.currentConference?.id?.let {

return baseDoc.collection("leads").document(it)

}

return baseDoc.collection("leads").document(demoID)

}

private val conferencesCollection: CollectionReference

get() = FirebaseFirestore.getInstance().

collection("conferences")

fun getUserProfile(callback: (AppUser) -> Unit) {

// Source can be CACHE, SERVER, or DEFAULT.

val source = Source.DEFAULT

baseDoc.get(source)

.addOnCompleteListener { task ->

if (task.isSuccessful) {

val document = task.result

if (document != null) {

printnLog(TAG, "Loaded profile for User

with UID: $uid successfully!")

val user = AppUser(task.result.data as

Map)

callback(user)

} else {

println("No profile set. Saving initial

profile...")

appUser = AppUser(fUser!!)

setUserProfile()

}

} else {

Log.w(TAG, "getUser:onCancelled",

task.exception)

}

}

}

解决方法:

使用val user = AppUser(task.result.data as Map< String,Any>)行,使Any变量可为空:

val user = AppUser(task.result.data as Map)

标签:kotlin,android

来源: https://codeday.me/bug/20191025/1924988.html

避开ns-3学习深坑:用sns3模块快速搭建GEO卫星通信仿真(附GitHub代码解读) 本文介绍了如何使用sns3模块快速搭建GEO卫星通信仿真环境,绕过复杂的ns-3底层细节。通过详细的Linux环境配置、sns3模块安装和示例代码解读,帮助开发者快速上手卫星通信仿真,并提供了常见问题的解决方案和性能优化技巧。 阅读详情

相关推荐

嵌入式系统中的轻量级压缩实践——miniLZO在STM32上的性能优化

本文深入探讨了miniLZO轻量级压缩算法在STM32嵌入式系统中的性能优化实践。通过对比无损压缩算法的性能特点,详细解析了miniLZO在内存占用、压缩速度方面的优势,并提供了STM32移植、参数调优及创新应用案例,帮助开发者在资源受限环境中实现高效数据压缩。

weixin_30776273的博客 90

lPointerException: null cannot be cast to non-null type android.util.SparseArray<android.view.View?>

kotlin的报错提示: java.lang.NullPointerException: null cannot be cast to non-null type android.util.SparseArray<android.view.View?> 报错信息可能是:null不能转换到非null类型SparseArray<android.view.View?> 先看看ViewHolder.kt object ViewHolder { operator fun <T

彬sir哥的博客 3851

从STM32转战华大HC32F4A0:我的踩坑实录与10个USART的灵活配置心得

本文分享了从STM32迁移至华大HC32F4A0的实战经验,重点解析了10个USART的灵活配置技巧及常见问题解决方案。通过对比STM32F407,详细介绍了HC32F4A0在外设灵活性、IO功能组设计及多串口应用中的优势,帮助开发者快速掌握国产芯片的开发要点。

weixin_30514745的博客 530

Kotlin报错:null cannot be cast to non-null type kotlin.Int

it.todo() //函数内使用it替代object对象访问属性和方法。it.todo() //object不为null,才会执行let函数。当a不为null时,执行大括号里的语句(it肯定不为null)如果a == null ,则为 null。= null,则a.b()如果 a 不是 b,则为 null。如果a 是 b,则 a as b。当a为null时,什么都不执行。如果a==null,抛出空指针。=null时,执行a。当a==null时,执行b。kotlin常用表达式let,?

Zhang Phil 1762

避坑指南:为什么你的conda环境装不上Mamba?从CUDA到ABI的深度排查

本文深入解析conda环境中安装Mamba架构时常见的CUDA版本冲突、ABI不匹配等问题,提供从基础检查到深度排查的系统化解决方案。针对`causal-conv1d`和`mamba-ssm`安装失败场景,详细讲解PyTorch版本绑定、编译器工具链兼容性等关键技术要点,并给出预编译wheel选择、动态链接库配置等实用修复方案。

weixin_33738555的博客 354

OpenAI Realtime API实时语音交互实战指南

实时语音交互是人机自然对话的核心能力,其本质在于构建低延迟、双向、流式协同的音频-语义闭环。它突破传统REST API的请求-响应范式,依托WebSocket实现毫秒级音频输入流(audio.delta)、模型生成流(text/audio.delta)与动态控制流(session.update)三重并行。该技术显著降低端到端延迟至300ms以内,支撑语音助手、智能客服、对话式教育等强实时场景。本文聚焦OpenAI Realtime API的工程落地,详解PCM音频流处理、VAD语音活动检测、AudioCon

weixin_32285357的博客 415

kotlin.TypeCastException: null cannot be cast to non-null type android.widget.TextView

在使用Kotlin写adapter的setOnItemClickListener事件的时候抛出了kotlin.TypeCastException: null cannot be cast to non-null type android.widget.TextView的异常,出错代码如下: 错误代码: (adapter.getViewByPosition(index,R.id.tv_menu_name) as TextView).textSize = 12f 正确写法: adapt...

Homjay的博客 6196

c\c++: Identifiers, modifier, qualifier, specifier, decorator; systemtap

文章目录参考英语含义在c、C++ 参考 c++ 标准 https://blog.csdn.net/tyronne/article/details/44016621 英语含义 modifier word or phrase that modifies (modify 2) another word or phrase 修饰语. qualifier (grammar) word, esp an adjective or adverb, that qualifies another word 修饰词; (尤指)形

mzhan017的博客 2457

arouter报错null cannot be cast to non-null type androidx.fragment.app.Fragment

使用arouter报错

qq_35974930的博客 516

GEE训练教程:基于Sentinel-2卫星的归一化建筑指数(NDBI)等的进行城市扩张分析

本文介绍利用Sentinel-2卫星数据和谷歌地球引擎平台监测印度卡姆鲁普都会区2018-2024年城市扩张的方法。通过计算归一化建筑指数(NDBI)、植被指数(NDVI)和水体指数(MNDWI),采用多阈值规则识别建设用地,并量化不同年份的城市扩张面积。代码实现了从数据预处理、指数计算到面积统计的完整流程,为城市扩张研究提供了可复制的技术方案。关键参数包括年份选择、云覆盖阈值和分类阈值,均可根据研究需求调整。该方法能有效追踪城市边界变化,为城市规划提供数据支持。

此星光明博客 142

QT应用编程: 编写低功耗BLE蓝牙调试助手(Android系统APP)

一、环境介绍 QT版本: 5.12.6 编译环境: win10 64位 目标系统: Android 完整工程源码下载地址(包含APK文件):https://download.csdn.net/download/xiaolong1126626497/19051696 二、功能介绍 本软件是一款BLE蓝牙串口调试助手,支持常规的发送和接收调试,BLE是低功耗类型蓝牙,在智能家居、物联网领域使用较多。BLE低功耗蓝牙一般不能直接使用手机进行连接,手机蓝牙默认都是工作在传统蓝牙模式,无法直接连接BL..

7680

kotlin.TypeCastException: null cannot be cast to non-null type android.support.v7.widget

java.lang.RuntimeException: Unable to start activity ComponentInfo{www.xl06.xyz/www.xl06.xyz.ui.MainActivity}: kotlin.TypeCastException: null cannot be cast to non-null type android.support.v7.widge...

一抹离愁 8353

081、空间降噪(Spatial Denoise)实战:双边滤波、非局部均值与BM3D在ISP中的调优

调参时,别只看PSNR/SSIM。找几个典型场景(夜景、人像、文字、天空),在真实设备上肉眼对比。我见过PSNR涨了2dB但图像看起来更差的案例——因为PSNR不惩罚纹理丢失。空间降噪这块,理论说再多,不如动手调一次。下次遇到噪点问题,先别急着上BM3D,试试双边滤波的自适应参数,说不定有惊喜。

zzfmlxs的博客 53

cannot be cast to android.graphics.drawable.BitmapDrawable

问题代码: holder.imageView.setImageBitmap(((BitmapDrawable) list.get(position) .getFileIcon()).getBitmap()); 这段代码的意思大概就是从列表中获取图标内容,再将DitmapDrawable类型转换成Bitmap类型,再放进holder.imageView中,在Android版本较高的系统上并不会报异常...

wljs17的博客 3794

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

java.lang.NoClassDefFoundError: kotlin/TypeCastException

这个问题引发的起因我记录在这里了:JAVA根据短链接获取真实链接 原因:引入okhttp依赖会导入两个jar包,一个是okhttp包,一个是okio包,okio2.0以后用kotlin重构了 Okio 2 is a major release that upgrades the library’s implementation language from Java to Kotlin. 同理okhttp3,主要是服务安卓开发,服务端依赖还是得用旧库 解决方案:降低Maven依赖的版本就好了 <!--

求生的码农博客 2314

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

出现java.lang.NullPointerException的可能原因及解决方案

综上所述,最常见的原因是对象未被正确初始化或者有 null 值的参数、数组或集合。因此,开发人员需要避免这些情况并进行适当的错误处理。

IT学习小镇 7万+

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

无涯教程-Kotlin - 安全转换

有时无法强制转换变量并引发异常,这称为不安全强制转换。不安全的强制转换由infix运算符as进行。无法将可为空的字符串(String?)强制转换为非nullabe字符串(String),这将引发异常。nullval strStringobjasStringprintlnstr上面的程序抛出异常:Exceptioninthread"main"kotlinnull。

无涯教程 1015

Binary XML file line #80 in **view** null cannot be cast to non-null type ***view**

fragment加载自定义view

qq_36975610的博客 605

typecast java_kotlin.TypeCastException: null cannot be cast to non-null type com.midsizemango.databa...

class EditNoteActivity : AppCompatActivity() { var note: Note? = null private val editNote: TextView? = null private val fabdrwble: Boolean? = null private val notesData: MutableList? = null privat...

weixin_27015375的博客 554

解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

解决方法: 第一行中cannot be cast to 后面的layoutparams就是你要的真正的layoutparams,比如这个 android.widget.FrameLayout$LayoutParams是错误的,而cannot be cast to后面的android.widget.AbsListView$LayoutParams是对的

jinjin_15的博客 5483

java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Int

Java小数点数字和百分号数字之间的转换小数点数字和百分号(百分比)数字之间的转换在证券金融业很常见,需要经常进行两者之间相互转换。Java小数点数字和百分号数字之间的转换_将浮点型转为百分比 java-CSDN博客。_kotlin向上取整。Java小数点数字和百分号数字之间的转换小数点数字和百分号(百分比)数字之间的转换在证券金融业很常见,需要经常进行两者之间相互转换。Java小数点数字和百分号数字之间的转换小数点数字和百分号(百分比)数字之间的转换在证券金融业很常见,需要经常进行两者之间相互转换。

Zhang Phil 959

null cannot be cast to non-null type android.databinding.ViewDataBinding

如果Build.gradle和Layout文件配置正确,仍无法生成ViewDataBinding类。 经测试,Gradle的sync无效,clean project无效,invalidate and restart无效,但是Build->Rebuild Project生效了。 还不行的话,使用ViewDataBinding抽象类的setVariable方法,也可以生效。 AS版本:3.1.3 gradle版本:3.1.3 转载于:https://www.cnblogs.com/acesui/

u013297881的专栏 1363

Kotlin 实战经验中的那些坑+最佳实践

“确认过“踩过坑”,遇上对的 kotlin”Num 1:方法入参是常量,不可修改 Java 与 Kotlin 互操中,Java 程序员会有点不适应class Main { /...

Android技术之家 2173

《Kotin 极简教程》第10章 Kotlin与Java互操作

第10章 Kotlin与Java互操作 《Kotlin极简教程》正式上架: 点击这里 &gt; 去京东商城购买阅读 点击这里 &gt; 去天猫商城购买阅读 非常感谢您亲爱的读者,大家请多支持!!!有任何问题,欢迎随时与我交流~ Kotlin is 100% interoperable with Java™ and Android™ 在前面的...

AI天才研究院 9096
上一篇: android解析doc文件,android解析doc,docx,xls,xlsx文件
下一篇: html document怎么转换成word,Doxillion Document Converter – 将 DOC、DOCX、PDF、WPS、Word、HTML文档格式互相转换...
桂能
博客等级 码龄8年 19粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值