Kotlin Parameter specified as non-null is null: method, kotlinnon-null

Source: Internet
Author: User

Kotlin Parameter specified as non-null is null: method, kotlinnon-null

When using Code-> Convert Java File to Kotlin File, pay attention to it. For example, I want to convert MyDialog. java to MyDialog. kt. The following error message is displayed:

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState

MyDialog. java

public class MyDialog extends Dialog {    public MyDialog(@NonNull Context context) {        super(context);    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);    }}

MyDialog. kt

class MyDialog(context: Context) : Dialog(context) {    override fun onCreate(savedInstanceState: Bundle) {        super.onCreate(savedInstanceState)    }}

With the error message, Intrinsics. checkParameterIsNotNull can naturally know how to change it.
MyDialog. kt after modification

class MyDialog(context: Context) : Dialog(context) {    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)    }}

Open MyDialog. kt [Tools-> Kotlin-> Show Kotlin Bytecode] and click Decomplie

public final class MyDialog extends Dialog {   protected void onCreate(@NotNull Bundle savedInstanceState) {      Intrinsics.checkParameterIsNotNull(savedInstanceState, "savedInstanceState");      super.onCreate(savedInstanceState);   }   public MyDialog(@NotNull Context context) {      Intrinsics.checkParameterIsNotNull(context, "context");      super(context);   }}

In the original method, the NotNull parameter will check the NULL pointer operation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.