小编jac*_*ast的帖子

奇怪的 kotlin checkNotNullParameter 错误

我们在 Firebase 上收到了 kotlin 方法崩溃的消息:

Fatal Exception: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter code
       at [redacted].DeliveryMethod.<init>(:2)
       at [redacted].DeliveryMethodsUpdater$addSingleDMInAd$clientCall$1.invokeSuspend(DeliveryMethodsUpdater.kt:121)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Run Code Online (Sandbox Code Playgroud)

模型是这样的:

class DeliveryMethod() {
    lateinit var code: String
    lateinit var name: String
    lateinit var description: String

var isAddressRequired: Boolean? = null
var image: JSONObject? = null
var isDefault: Boolean = false

constructor(code: String) : this() {
    this.code = code
}

constructor(code: String, name: String, description: String, …
Run Code Online (Sandbox Code Playgroud)

kotlin

3
推荐指数
1
解决办法
704
查看次数

Android:layout_width和height裁剪我的图片

我有这个小布局我定义插入我的应用程序的每个页面:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageButton
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="10dp"
    android:background="@null"
    android:src="@drawable/sa_info"
    android:layout_alignParentRight="true"/>
Run Code Online (Sandbox Code Playgroud)

我的sa_info.png是118x118,但我希望它在屏幕上显得更小.如果我尝试将图像按钮的宽度和高度设置为所需的大小(比方说48dp),当我运行应用程序时生成的图像被裁剪到中心: 原始图像 裁剪图像

因此,我必须获得所需结果的唯一方法是将图像本身缩放到所需的分辨率.我做错了什么,有更好的方法吗?

layout android imagebutton

2
推荐指数
1
解决办法
4514
查看次数

Java:在最终类中实现接口的类

这可能是一个愚蠢的问题,但我在这里感到困惑.我有以下情况:

Main.java

public class Main {

    public static void main (String args[]){
        GenericTag[] arr = new GenericTag[2];
        arr[0] = new Authentication("", "", "", "");
        arr[1] = new Document("", "", "", "");
        byte[] foo= Base64.decodeBase64(XmlBuilder.generate(arr));
        System.out.println(new String(foo));
    }
Run Code Online (Sandbox Code Playgroud)

XmlBuilder.java

public final class XmlBuilder {
    private static final String OPEN_TAG = "";
    private static final String CLOSE_TAG = "";

    public static byte[] generate(GenericTag[] tags){

        String xml = OPEN_TAG;
        for(int i=0; i<tags.length; i++){
            xml += tags[i].xml;
        }
        xml += CLOSE_TAG;

        return Base64.encodeBase64(xml.getBytes());
    } …
Run Code Online (Sandbox Code Playgroud)

java interface class

2
推荐指数
1
解决办法
327
查看次数

GCC:对 xxx 的未定义引用

我知道这个问题已经被问了很多次了,但我无法真正解决它......所以我有一个src文件夹,其中包含我的main.c源代码,一个存储srclib我的文件的文件夹,以及一个存储我的文件的目录。现在 makefile 正确编译了 lib 并将文件放入文件夹中。包括这样的库:lib.cincludelib.hlib.alibmain.c

#include "lib.h"
Run Code Online (Sandbox Code Playgroud)

它是用-I ../include选项编译的,但是当我编译它时,我得到undefined reference to xxx库中每个函数的错误

那么我错过了什么?

c linker gcc makefile undefined-reference

0
推荐指数
1
解决办法
2718
查看次数

Android:未触发与包相关的意图

我正在开发一个启动器应用程序,我刚刚添加了一个广播接收器,我将使用它来更新应用程序列表。我最初尝试接收ACTION_PACKAGE_ADDEDACTION_PACKAGE_REMOVED因为它们似乎足以胜任这项工作,但没有一个被解雇,所以我添加了我认为有用的所有其他与包相关的操作,并尝试在活动中注册它们:

val intentFilter = IntentFilter()
        intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED)
        intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED)
        intentFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED)
        intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL)
        intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED)
        val rec = AppsInstallationsReceiver()
        registerReceiver(rec, intentFilter)
Run Code Online (Sandbox Code Playgroud)

并体现:

<receiver android:name=".core.installed_apps.AppsInstallationsReceiver">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
                <action android:name="android.intent.action.PACKAGE_INSTALL" />
                <action android:name="android.intent.action.PACKAGE_REPLACED" />
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>
Run Code Online (Sandbox Code Playgroud)

接收器本身没什么特别的:

class AppsInstallationsReceiver : BroadcastReceiver() {

    override fun onReceive(p0: Context?, p1: Intent?) {
        //TODO
    }
}
Run Code Online (Sandbox Code Playgroud)

事实证明,我只收到PACKAGE_FULLY_REMOVED并且仅当它在清单中注册时才收到。现在这已经足够好了,但我需要一种方法来知道何时安装新应用程序。由于这是一个启动器应用程序,因此此功能至关重要。为什么我没有收到任何东西?当然,该活动仍然存在于后台,因为它被用作启动器。

android android-intent android-launcher

0
推荐指数
1
解决办法
1006
查看次数