Tag: android toast

从Fragment调用Anko toast()方法会导致java.lang.NoSuchMethodError

当我从Android Fragment调用toast(“Toast的消息文本”)时出现以下错误: java.lang.NoSuchMethodError:无虚方法getActivity()Landroid / app / Activity; 在类Landroid / support / v4 / app / Fragment中; 或者它的超类(“android.support.v4.app.Fragment”声明出现在文件类名索引中) 我使用的是Anko v0.9.1和Kotlin 1.0.6 什么可能是这次崩溃的原因? 标准的Android吐司工作得很好。 另外Toast()函数在Activity内工作。

Android Toast无法正常工作(应用程序崩溃)

我不确定这是IDE问题还是我的编码问题。 这个应用程序几乎是我在网上跟随的一个,但我的应用程序不断崩溃。 链接到源代码: https : //github.com/Gusri/AgeValidated 。 我的代码几乎与此相同。 XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" tools:context="min.com.nyp.sit.myapplication.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Your name" /> <EditText android:id="@+id/editTextName" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Age" /> <EditText android:id="@+id/editTextAge" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/buttonEnter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Validate"/> </LinearLayout> 科特林代码 package min.com.nyp.sit.myapplication import android.support.v7.app.AppCompatActivity import android.os.Bundle import […]

从Fragment调用Anko toast()方法会导致java.lang.NoSuchMethodError

当我从Android Fragment调用toast(“Toast的消息文本”)时出现以下错误: java.lang.NoSuchMethodError:无虚方法getActivity()Landroid / app / Activity; 在类Landroid / support / v4 / app / Fragment中; 或者它的超类(“android.support.v4.app.Fragment”声明出现在文件类名索引中) 我使用的是Anko v0.9.1和Kotlin 1.0.6 什么可能是这次崩溃的原因? 标准的Android吐司工作得很好。 另外Toast()函数在Activity内工作。