草庐IT

kotlin.notimplementederror

全部标签

android - kotlin 从文件读取到字节数组

如何将字节读入字节数组?在java中,我曾经将字节数组初始化为byte[]b=newbyte[100],然后将其传递给相应的方法。但是在Kotlin中,我无法用缓冲区应该有多少字节来初始化ByteArray。换句话说,我该如何使用这个功能?:https://developer.android.com/reference/kotlin/java/io/RandomAccessFile#read(kotlin.ByteArray) 最佳答案 最简单的方法是使用File("aaa").readBytes()那个会将整个文件读入ByteAr

android - 对于 204 无内容响应,Retrofit2 在 kotlin 中返回 null Unit

我正在使用Retrofit2.0.2通过以下界面将数据发布到服务器:@POST("/path/to/post")funpostData(/*args*/):Observable并收到服务器的成功响应。05-0921:20:21.7702311723224DOkHttp:-->POSThttps://myserver.com/api/notifications/123/markReadhttp/1.105-0921:20:21.7702311723224DOkHttp:Content-Length:005-0921:20:21.7702311723224DOkHttp:User-Agen

Java/安卓/ Kotlin : Reflection on private Field and call public methods on it

是否可以使用反射来访问对象的私有(private)字段并在该字段上调用公共(public)方法?一个classHello{privateWorldword}classWorld{publicBlaBlaBlafoo()}Helloh=newHello()Worldworld=reflectontheh//Andthenworld.foo() 最佳答案 可以使用反射使私有(private)字段可访问。以下示例(均用Kotlin编写)展示了它...使用Java反射:valhello=Hello()valf=hello::class.ja

android - 如何更改 kotlin fragment 类中的 ActionBar 标题?

我是kotlin中android开发的新手。我尝试了以下代码来更改我的fragment中的操作栏标题。它不起作用。请帮忙overridefunonViewCreated(view:View?,savedInstanceState:Bundle?){super.onViewCreated(view,savedInstanceState)activity.actionBar?.title="Example1"countBtn.setOnClickListener(this)toastBtn.setOnClickListener(this)randomBtn.setOnClickListen

java - 为什么我的错误被 Kapt 和 Kotlin 掩盖了?如何增加错误限制?

我遇到了涉及Android数据绑定(bind)、Room和Dagger的问题。如果任何代码生成步骤失败,所有这些都会在编译时生成带有错误的代码,显示未找到对象。这会导致很多很多错误。错误数可以超过Java错误限制。因此,错误的根源被埋没了。它在错误列表中不可见。增加Java错误限制不起作用,因为Kotlin注释处理器Kapt忽略了它。如何提高Java错误限制? 最佳答案 我在这里找到了答案:http://kotlinlang.org/docs/reference/kapt.html#java-compiler-options需要将以

android - 在 kotlin 中连接两个字节数组的简单方法?

在Kotlin中连接两个字节数组的最简单方法是什么?考虑一下,valx=ByteArray(a);valy=ByteArray(b);帮我把两个字节数组x,y拼接起来,存入另一个ByteArray? 最佳答案 有一个运算符函数plus对于ByteArray(以及所有其他数组)operatorfunByteArray.plus(elements:ByteArray):ByteArrayReturnsanarraycontainingallelementsoftheoriginalarrayandthenallelementsofthe

android - Kotlin 协程处理错误和实现

第一次使用协程。需要帮助。这是我的流程:Presenter想要登录所以调用RepositoryInterface。Repository实现RepositoryInterface。所以Repository调用APIInterface。APIInterface由APIInterfaceImpl实现。APIInterfaceImpl最后调用MyRetrofitInterface。这是流程图:Presenter->Repository->APIInterfaceImpl->MyRetrofitInterface一旦我收到登录响应:APIInterfaceImpl->Repository->将数

带有 Kotlin 的 Android - 如何使用 HttpUrlConnection

我试图从AsyncTask中的url获取数据,但在创建HttpUrlConnection的新实例时出现错误。Java上类似这样的东西URLurl=newURL("http://www.android.com/");HttpURLConnectionurlConnection=(HttpURLConnection)url.openConnection();try{InputStreamin=newBufferedInputStream(urlConnection.getInputStream());readStream(in);finally{urlConnection.disconne

Android - 在 Kotlin 中声明和使用 View

我正在尝试将kotlin用于android并尝试像这样声明Linearlayout:internalvarlinlay_SuccessfulPayment:LinearLayout=null!!internalvarlinlay_failPayment:LinearLayoutlinlay_SuccessfulPayment=findViewById(R.id.linlay_SuccessfulPayment)asLinearLayoutlinlay_failPayment=findViewById(R.id.linlay_failPayment)asLinearLayout但是在日志

java - 将 android hashmap 转换为 kotlin

我有一个JavaHashMap填充为HashMapmyMMap=newHashMap();for(inti=0;i我正在尝试将其转换为Kotlin。我尝试了下面的方法,但我得到的是空值。varmyMap:HashMap?=nullfor(iinobjects){//myMap?.put(i,objects.indexOf(i))myMap?.put("sample",3)System.out.println("myMapInForLoop"+myMap)}它打印I/System.out:myMapInForLoopnull。我试过使用hashMapOf函数,但它只允许1个值,所以我不能