应用在使用Intent从Java Activity启动Kotlin活动时崩溃。

huangapple go评论69阅读模式
英文:

App crashes whenever a Kotlin activity is launched from a Java Activity while using Intent

问题

以下是翻译好的内容:

这个应用目前有三个活动,一个登录活动,一个注册活动,以及一个用 Kotlin 编写的名为 Bookjamroom 的活动。Bookjamroom 活动应该在点击登录按钮时显示,但每当我这样做时,应用就会强制关闭。

Log Cat 错误:

  • 2020-10-15 20:17:53.047 12954-12981/com.example.jamsecure E/eglCodecCommon: glUtilsParamSize: 未知参数 0x000082da
  • 2020-10-15 20:17:53.303 12954-12981/com.example.jamsecure D/EGL_emulation: eglMakeCurrent: 0xebb840c0: 版本 3 1 (tinfo 0xebb832e0)
  • 2020-10-15 20:18:03.883 12954-12954/com.example.jamsecure D/AndroidRuntime: 关闭虚拟机 2020-10-15 20:18:03.889
  • 12954-12954/com.example.jamsecure E/AndroidRuntime: 致命异常:
  • 主进程:com.example.jamsecure,PID:12954
  • java.lang.RuntimeException: 无法实例化活动 ComponentInfo{com.example.jamsecure/com.example.jamsecure.Bookjamroom}:java.lang.NullPointerException: 尝试调用虚拟方法 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' 但对象引用为空
  • 引起的原因:java.lang.NullPointerException:尝试调用虚拟方法 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' 但对象引用为空
  • ...(以下为详细堆栈跟踪)

Kotlin .kt 类代码

package com.example.jamsecure

import android.os.Bundle
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.floatingactionbutton.FloatingActionButton

class Bookjamroom : AppCompatActivity() {
    // 这里是类的定义,包括变量和函数,省略了具体内容
}

调用 Kotlin 类的 Java 代码

import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    // 这里是类的定义,包括变量和函数,省略了具体内容
}

Kotlin 活动的 XML 布局文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back3"
    tools:context=".Bookjamroom">

    <!-- 这里是布局的定义,包括视图和约束,省略了具体内容 -->

</androidx.constraintlayout.widget.ConstraintLayout>

Java 布局文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back3"
    tools:context=".MainActivity">

    <!-- 这里是布局的定义,包括视图和约束,省略了具体内容 -->

</androidx.constraintlayout.widget.ConstraintLayout>

希望这些翻译能够帮助你理解你提供的代码和信息。如果你需要进一步的帮助,请随时提问。

英文:

This app currently has three activities, a Login activity, Register activity and an activity written in Kotlin called the Bookjamroom activity. The Bookjamroom activity is supposed to be displayed On click of the login button, but whenever i do so the app forcefully shuts down.

Log Cat Error:

 - 2020-10-15 20:17:53.047 12954-12981/com.example.jamsecure
   E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
   2020-10-15 20:17:53.047 12954-12981/com.example.jamsecure
   E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
   2020-10-15 20:17:53.303 12954-12981/com.example.jamsecure
   D/EGL_emulation: eglMakeCurrent: 0xebb840c0: ver 3 1 (tinfo
   0xebb832e0) 2020-10-15 20:18:03.883 12954-12954/com.example.jamsecure
   D/AndroidRuntime: Shutting down VM 2020-10-15 20:18:03.889
   12954-12954/com.example.jamsecure E/AndroidRuntime: FATAL EXCEPTION:
   main
       Process: com.example.jamsecure, PID: 12954
       java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.jamsecure/com.example.jamsecure.Bookjamroom}:
   java.lang.NullPointerException: Attempt to invoke virtual method
   &#39;android.content.pm.ApplicationInfo
   android.content.Context.getApplicationInfo()&#39; on a null object
   reference
           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
           at android.app.ActivityThread.-wrap11(Unknown Source:0)
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
           at android.os.Handler.dispatchMessage(Handler.java:106)
           at android.os.Looper.loop(Looper.java:164)
           at android.app.ActivityThread.main(ActivityThread.java:6494)
           at java.lang.reflect.Method.invoke(Native Method)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
        Caused by: java.lang.NullPointerException: Attempt to invoke virtual method &#39;android.content.pm.ApplicationInfo
   android.content.Context.getApplicationInfo()&#39; on a null object
   reference
           at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:152)
           at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:157)
           at android.content.Context.obtainStyledAttributes(Context.java:655)
           at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:839)
           at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
           at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:630)
           at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:223)
           at com.example.jamsecure.Bookjamroom.&lt;init&gt;(Bookjamroom.kt:12)
           at java.lang.Class.newInstance(Native Method)
           at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)&#160;
           at android.app.ActivityThread.-wrap11(Unknown Source:0)&#160;
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)&#160;
           at android.os.Handler.dispatchMessage(Handler.java:106)&#160;
           at android.os.Looper.loop(Looper.java:164)&#160;
           at android.app.ActivityThread.main(ActivityThread.java:6494)&#160;
           at java.lang.reflect.Method.invoke(Native Method)&#160;
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)&#160;
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Kotlin .kt class code

    package com.example.jamsecure

import android.os.Bundle
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.floatingactionbutton.FloatingActionButton

class Bookjamroom : AppCompatActivity() {
    private val bfa = findViewById&lt;FloatingActionButton&gt;(R.id.bfa)
    private val bnj = findViewById&lt;FloatingActionButton&gt;(R.id.bnj)
    private val bp = findViewById&lt;FloatingActionButton&gt;(R.id.bp)
    private val bhb = findViewById&lt;FloatingActionButton&gt;(R.id.bhb)
    private val rotateOpen: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.rotate_open_anim) }
    private val rotateClose: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.rotate_close_anim) }
    private val fromBottom: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.from_bottom) }
    private val toBottom: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.to_bottom) }
    private var clicked = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_book_jam_room)
        bfa?.setOnClickListener {
            onAddButtonClicked()
        }
        bnj?.setOnClickListener {
            Toast.makeText(this, &quot;1button is clicked&quot;, Toast.LENGTH_SHORT).show()

        }
        bp?.setOnClickListener {
            Toast.makeText(this, &quot;2button is clicked&quot;, Toast.LENGTH_SHORT).show()

        }
        bhb?.setOnClickListener {
            Toast.makeText(this, &quot;3button is clicked&quot;, Toast.LENGTH_SHORT).show()

        }

    }

    private fun onAddButtonClicked() {
        setVisibility(clicked)
        setAnimation(clicked)
        clicked = !clicked
    }

    private fun setVisibility(clicked: Boolean) {
        if (!clicked) {
            bnj.visibility = View.VISIBLE
            bp.visibility = View.VISIBLE
            bhb.visibility = View.VISIBLE
        } else {
            bnj.visibility = View.INVISIBLE
            bp.visibility = View.INVISIBLE
            bhb.visibility = View.INVISIBLE
        }
    }

    private fun setAnimation(clicked: Boolean) {
        if (!clicked) {
            bnj.startAnimation(fromBottom)
            bp.startAnimation(fromBottom)
            bhb.startAnimation(fromBottom)
            bfa.startAnimation(rotateOpen)
        } else {
            bnj.startAnimation(toBottom)
            bp.startAnimation(toBottom)
            bhb.startAnimation(toBottom)
            bfa.startAnimation(rotateClose)
        }
    }
}                        

Java Code that calls the Kotlin class

import android.widget.TextView;

import org.jetbrains.annotations.NotNull;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView textView = findViewById(R.id.reg);
        Button lbtn = findViewById(R.id.lb);
       lbtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
             
                Intent i = new Intent(MainActivity.this,Bookjamroom.class);
                startActivity(i);
            }
        });
        SpannableString spannableString = new SpannableString(&quot;New user? tap here to register!&quot;);
        ClickableSpan span = new ClickableSpan() {
            @Override
            public void onClick(@NotNull View v) {
                Intent intent = new Intent(MainActivity.this, Register.class);
                startActivity(intent);
            }
        };
        spannableString.setSpan(span, 0, 31, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        textView.setText(spannableString);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

XML file of Kotlin Activity's Layout

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:background=&quot;@drawable/back3&quot;
    tools:context=&quot;.Bookjamroom&quot;&gt;

    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id=&quot;@+id/bfa&quot;
        android:layout_width=&quot;50dp&quot;
        android:layout_height=&quot;50dp&quot;
        android:backgroundTint=&quot;@color/colorPrimary&quot;
        android:clickable=&quot;true&quot;
        android:focusable=&quot;true&quot;
        android:tint=&quot;@android:color/white&quot;

        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
        app:layout_constraintEnd_toEndOf=&quot;parent&quot;
        app:layout_constraintHorizontal_bias=&quot;0.955&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot;
        app:layout_constraintVertical_bias=&quot;0.976&quot;
        app:srcCompat=&quot;@drawable/b_add&quot; /&gt;

    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id=&quot;@+id/bnj&quot;
        android:layout_width=&quot;50dp&quot;
        android:layout_height=&quot;50dp&quot;
        android:layout_marginBottom=&quot;8dp&quot;
        android:backgroundTint=&quot;@color/colorPrimary&quot;
        android:clickable=&quot;true&quot;
        android:focusable=&quot;true&quot;
        android:tint=&quot;@android:color/white&quot;
        android:visibility=&quot;invisible&quot;
        app:layout_constraintBottom_toTopOf=&quot;@+id/bfa&quot;
        app:layout_constraintEnd_toEndOf=&quot;@+id/bfa&quot;
        app:srcCompat=&quot;@drawable/b_new_jam&quot; /&gt;

    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id=&quot;@+id/bp&quot;
        android:layout_width=&quot;50dp&quot;
        android:layout_height=&quot;50dp&quot;
        android:layout_marginBottom=&quot;8dp&quot;
        android:backgroundTint=&quot;@color/colorPrimary&quot;
        android:clickable=&quot;true&quot;
        android:focusable=&quot;true&quot;
        android:tint=&quot;@android:color/white&quot;
        android:visibility=&quot;invisible&quot;
        app:layout_constraintBottom_toTopOf=&quot;@+id/bnj&quot;
        app:layout_constraintEnd_toEndOf=&quot;@+id/bnj&quot;
        app:srcCompat=&quot;@drawable/b_past&quot; /&gt;

    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id=&quot;@+id/bhb&quot;
        android:layout_width=&quot;50dp&quot;
        android:layout_height=&quot;50dp&quot;
        android:layout_marginBottom=&quot;7dp&quot;
        android:backgroundTint=&quot;@color/colorPrimary&quot;
        android:clickable=&quot;true&quot;
        android:focusable=&quot;true&quot;
        android:tint=&quot;@android:color/white&quot;
        android:visibility=&quot;invisible&quot;
        app:layout_constraintBottom_toTopOf=&quot;@+id/bp&quot;
        app:layout_constraintEnd_toEndOf=&quot;@+id/bp&quot;
        app:srcCompat=&quot;@drawable/b_helpbot&quot; /&gt;

    &lt;TextView
        android:id=&quot;@+id/textView9&quot;
        android:layout_width=&quot;157dp&quot;
        android:layout_height=&quot;145dp&quot;
        android:layout_marginTop=&quot;64dp&quot;
        android:text=&quot;@string/welcom&quot;
        app:layout_constraintEnd_toEndOf=&quot;parent&quot;
        app:layout_constraintHorizontal_bias=&quot;0.46&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

XML of Java Layout

 &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
        xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
        xmlns:tools=&quot;http://schemas.android.com/tools&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;
        android:background=&quot;@drawable/back3&quot;
        tools:context=&quot;.MainActivity&quot;&gt;
    
        &lt;Button
            android:id=&quot;@+id/lb&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:text=&quot;@string/login&quot;
            android:textSize=&quot;24sp&quot;
            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintHorizontal_bias=&quot;0.449&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
    
        &lt;EditText
            android:id=&quot;@+id/editTextTextPersonName&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:ems=&quot;10&quot;
            android:fontFamily=&quot;sans-serif-black&quot;
            android:hint=&quot;@string/enter_username&quot;
            android:importantForAutofill=&quot;no&quot;
            android:inputType=&quot;textPersonName&quot;
            android:textColor=&quot;#F6F6F6&quot;
            android:textColorHint=&quot;#FFFFFF&quot;
            android:textSize=&quot;24sp&quot;
            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintHorizontal_bias=&quot;0.496&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintTop_toTopOf=&quot;parent&quot;
            app:layout_constraintVertical_bias=&quot;0.262&quot; /&gt;
    
        &lt;EditText
            android:id=&quot;@+id/tpw&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:ems=&quot;10&quot;
            android:fontFamily=&quot;sans-serif-black&quot;
            android:hint=&quot;@string/enter_password&quot;
            android:importantForAutofill=&quot;no&quot;
            android:inputType=&quot;textPassword&quot;
            android:textColor=&quot;#F6F6F6&quot;
            android:textColorHint=&quot;#FFFDFD&quot;
            android:textSize=&quot;24sp&quot;
            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintHorizontal_bias=&quot;0.496&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintTop_toTopOf=&quot;parent&quot;
            app:layout_constraintVertical_bias=&quot;0.377&quot; /&gt;
    
        &lt;TextView
            android:id=&quot;@+id/textView&quot;
            android:layout_width=&quot;360dp&quot;
            android:layout_height=&quot;105dp&quot;
            android:fontFamily=&quot;sans-serif-black&quot;
            android:text=&quot;@string/login_sign_up&quot;
            android:textColor=&quot;#FFFFFF&quot;
            android:textSize=&quot;36sp&quot;
            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintHorizontal_bias=&quot;1.0&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintTop_toTopOf=&quot;parent&quot;
            app:layout_constraintVertical_bias=&quot;0.065&quot; /&gt;
    
        &lt;TextView
            android:id=&quot;@+id/reg&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:text=&quot;@string/new_user_tap_here_to_register&quot;
            android:textColor=&quot;#FFFFFF&quot;
            android:textColorHint=&quot;#FFFEFE&quot;
            android:textSize=&quot;24sp&quot;
            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintHorizontal_bias=&quot;0.494&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintTop_toTopOf=&quot;parent&quot;
            app:layout_constraintVertical_bias=&quot;0.852&quot; /&gt;
    &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

PS: This is my first post here at stack overflow, please excuse me if I have made any discrepancies, Thank you. Also the classes/activities are declared in the Manifest. And there isn't any issue with the Anim files.

答案1

得分: 0

你应该在onCreate方法中实例化视图。

private var bfa: FloatingActionButton? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_book_jam_room)
    bfa = findViewById<FloatingActionButton>(R.id.bfa)
}

或者可以直接通过id访问:

import kotlinx.android.synthetic.main.activity_book_jam_room.*

class Bookjamroom : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_book_jam_room)
        bfa?.setOnClickListener {
            onAddButtonClicked()
        }
    }
}
英文:

You should instantiate views in onCreate method.

private var bfa: FloatingActionButton? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_book_jam_room)
    bfa = findViewById&lt;FloatingActionButton&gt;(R.id.bfa)
}

or use access directly by id:

import kotlinx.android.synthetic.main.activity_book_jam_room.*

class Bookjamroom : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_book_jam_room)
        bfa?.setOnClickListener {
            onAddButtonClicked()
        }
    }

答案2

得分: 0

在你的 Kotlin 活动中尝试以下更改:

class Bookjamroom : AppCompatActivity() {
private lateinit var bfa: FloatingActionButton 
private lateinit var bnj: FloatingActionButton 
private lateinit var bp : FloatingActionButton
private lateinit var bhb : FloatingActionButton

然后在 onCreate 方法中:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_book_jam_room)

        bfa = findViewById<FloatingActionButton>(R.id.bfa)
        bnj = findViewById<FloatingActionButton>(R.id.bnj)
        bp = findViewById<FloatingActionButton>(R.id.bp)
        bhb = findViewById<FloatingActionButton>(R.id.bhb)

        bfa?.setOnClickListener {
            onAddButtonClicked()
        }
        bnj?.setOnClickListener {
            Toast.makeText(this, "1button is clicked", Toast.LENGTH_SHORT).show()

        }
        bp?.setOnClickListener {
            Toast.makeText(this, "2button is clicked", Toast.LENGTH_SHORT).show()

        }
        bhb?.setOnClickListener {
            Toast.makeText(this, "3button is clicked", Toast.LENGTH_SHORT).show()

        }

    }
英文:

Try the following change on your kotlin activity.

class Bookjamroom : AppCompatActivity() {
private lateinit var bfa: FloatingActionButton 
private lateinit var bnj: FloatingActionButton 
private lateinit var bp : FloatingActionButton
private lateinit var bhb : FloatingActionButton

then onCreate:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_book_jam_room)

        bfa = findViewById&lt;FloatingActionButton&gt;(R.id.bfa)
        bnj = findViewById&lt;FloatingActionButton&gt;(R.id.bnj)
        bp = findViewById&lt;FloatingActionButton&gt;(R.id.bp)
        bhb = findViewById&lt;FloatingActionButton&gt;(R.id.bhb)

        bfa?.setOnClickListener {
            onAddButtonClicked()
        }
        bnj?.setOnClickListener {
            Toast.makeText(this, &quot;1button is clicked&quot;, Toast.LENGTH_SHORT).show()

        }
        bp?.setOnClickListener {
            Toast.makeText(this, &quot;2button is clicked&quot;, Toast.LENGTH_SHORT).show()

        }
        bhb?.setOnClickListener {
            Toast.makeText(this, &quot;3button is clicked&quot;, Toast.LENGTH_SHORT).show()

        }

    }

</details>



huangapple
  • 本文由 发表于 2020年10月15日 23:08:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/64374582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定