Getting this Error
kotlin.NotImplementedError: An operation is not implemented: not implemented
I am implementing an ImageButton click listener
Requirement :- I want to perform an action on imagebutton click , but getting the above mentioned error
Correct me and also if there is any other work around to implement imagebutton click listener, do provide it , Thanks
Here is the fragment
java class
class FragmentClass : Fragment(), View.OnClickListener {
override fun onClick(v: View?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
when (v?.id) {
R.id.back_icon -> {
Toast.makeText(activity, "back button pressed", Toast.LENGTH_SHORT).show()
activity.onBackPressed()
}
else -> {
}
}
}
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view: View = inflater!!.inflate(R.layout.fragment_class, container,
false)
val activity = getActivity()
var input_name = view.findViewById(R.id.input_name) as EditText
var tv_addbucket = view.findViewById(R.id.tv_addbucket) as TextView
val back_icon: ImageButton = view.findViewById(R.id.back_icon)
back_icon.setOnClickListener(this)
tv_addbucket.setOnClickListener(View.OnClickListener {
Toast.makeText(activity, input_name.text, Toast.LENGTH_SHORT).show()
})
return view;
}
}
and then the fragment_class. xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:padding="10dp">
<ImageButton
android:id="@+id/back_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#0000"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:src="@drawable/back_icon" />
<TextView
android:id="@+id/tv_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Add Bucket" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="60dp">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Bucket Name"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/tv_addbucket"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="@drawable/blue_stroke_background"
android:gravity="center"
android:padding="15dp"
android:text="Add"
android:textColor="@color/white" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
Ealrann opened this issue
Jul 19, 2018
· 2 comments
Comments
Hello,
I got a recurring error when I use the colorButton: If I drag and drop (in fact if I move too fast when I click, whatever) it, I will got the following exception:
Exception in thread "main" kotlin.NotImplementedError: An operation is not implemented.
at imgui.imgui.imgui_dragAndDrop$DefaultImpls.setDragDropPayload(drag & Drop.kt:126)
at imgui.ImGui.setDragDropPayload(imgui.kt:45)
at imgui.imgui.imgui_widgetsColorEditorPicker$DefaultImpls.colorButton(widgets colorEditorPicker.kt:646)
at imgui.ImGui.colorButton(imgui.kt:45)
at org.sheepy.vulkan.sand.graphics.SandUIDescriptor.newFrame(SandUIDescriptor.java:110)
at org.sheepy.vulkan.imgui.ImGuiPipeline.newFrame(ImGuiPipeline.java:377)
at org.sheepy.vulkan.sand.pipelinepool.RenderPipelinePool.execute(RenderPipelinePool.java:74)
at org.sheepy.vulkan.sand.SandApplication.drawFrame(SandApplication.java:169)
at org.sheepy.vulkan.VulkanApplication.mainLoop(VulkanApplication.java:125)
at org.sheepy.vulkan.sand.SandApplication.mainLoop(SandApplication.java:128)
at org.sheepy.vulkan.VulkanApplication.run(VulkanApplication.java:63)
at org.sheepy.vulkan.sand.SandApplication.main(SandApplication.java:178)
Not a big problem, I just open an issue to track it.
I use the last Snapshot «v1.62-beta-02».
Yeah, dragAndDrop is kind of tricky, that’s why I put a TODO()
in the code, hoping that I’d fix that before anyone trigger that. But I was wrong
Try 3653ce4, drag and drop is still bugged, but at least it shouldn’t throw anything
Thank you very much, it does the trick 👍
Ealrann
added a commit
to Ealrann/Lily-Vulkan
that referenced
this issue
Jul 21, 2018
Ealrann
added a commit
to Ealrann/Lily-Vulkan
that referenced
this issue
Oct 21, 2018
2 participants
Encountering the "The Method or Operation is not Implemented" error can be quite frustrating, especially when you're not sure what's causing it. This guide aims to provide a step-by-step solution to help you fix this error, as well as provide answers to common questions related to the issue.
## Table of Contents
- [Understanding the Error](#understanding-the-error)
- [Step-by-step Solution](#step-by-step-solution)
- [FAQs](#faqs)
- [Related Links](#related-links)
<a name="understanding-the-error"></a>
## Understanding the Error
The "Method or Operation is not Implemented" error usually occurs when a method, function, or operation is called in a program, but its implementation is missing or incomplete. This error can happen in various programming languages, including [C#](https://docs.microsoft.com/en-us/dotnet/csharp/), [Java](https://www.oracle.com/java/technologies/), and [Python](https://www.python.org/).
<a name="step-by-step-solution"></a>
## Step-by-step Solution
Follow these steps to resolve the "Method or Operation is not Implemented" error:
1. **Locate the Error**: Identify the line of code where the error is occurring. The error message should provide the line number and file name.
2. **Check the Method or Operation**: Verify if the method or operation is defined within the code or if it's being imported from an external library or package. If it's defined within the code, ensure that it's implemented correctly.
3. **Verify Inheritance**: If the method or operation is part of an interface or an abstract class, ensure that the class implementing the interface or inheriting from the abstract class has provided a concrete implementation for the method.
4. **Inspect External Libraries**: If the method or operation comes from an external library or package, verify that the library is properly installed and imported. Additionally, check the library's documentation to ensure it supports the method or operation being called.
5. **Update the Library**: If the error persists, try updating the library or package to the latest version. This can resolve compatibility issues and ensure that the method or operation is implemented correctly.
<a name="faqs"></a>
## FAQs
<a name="faq1"></a>
### Why does the 'Method or Operation is not Implemented' error occur?
The error occurs when a method, function, or operation is called in a program, but its implementation is missing or incomplete.
<a name="faq2"></a>
### How can I find the source of the error?
The error message should provide the line number and file name where the error is occurring. Look for the method, function, or operation that is causing the issue.
<a name="faq3"></a>
### How can I fix the error if it's related to an external library?
Ensure that the library is properly installed and imported. Check the library's documentation to ensure it supports the method or operation being called, and update the library to the latest version if necessary.
<a name="faq4"></a>
### What if the error is caused by an inherited method?
Make sure that the class implementing the interface or inheriting from the abstract class has provided a concrete implementation for the method.
<a name="faq5"></a>
### How can I prevent this error from happening in the future?
To avoid this error, make sure that all methods, functions, and operations are implemented correctly within your code and that external libraries are properly installed, imported, and up-to-date.
<a name="related-links"></a>
## Related Links
- [C# Programming Yellow Book](https://www.robmiles.com/c-yellow-book/)
- [Java Language Documentation](https://docs.oracle.com/en/java/javase/index.html)
- [Python Documentation](https://docs.python.org/3/)
// Пользовательский интерфейс
interface OnTestCallback{
fun onTest()
}
// Используйте методы ярлыка для генерации методов в интерфейсе
setOnTestCallback(object :OnTestCallback{
override fun onTest() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
Вышеупомянутые сцены могут быть знакомы маленьким друзьям.Когда мы используем метод ярлыка для создания метода интерфейса, в методе появится следующее предложение:
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
Тогда многие друзья могут проигнорировать это и позволить ему существовать, а затем, когда мы доберемся доsetOnTestCallback(object :OnTestCallback{...})
На этом этапе вы обнаружите, что программа аварийно завершает работу и выдает исключение! (Неудивительно: улыбка
Ниже приведено исключение:
NotImplementedError: An operation is not implemented: not implemented
Так почему это? Почему? Почему?
Посмотрим на скомпилированныйjava
Код
this.setOnTestCallback((Test.OnTestCallback)(new Test.OnTestCallback() {
public void onTest() {
String var1 = "not implemented";
throw (Throwable)(new NotImplementedError("An operation is not implemented: " + var1));
}
}));
Видя это, все ясно,koltin
серединаTODO
Будет во время компиляции, вjava
Создать один вВыбросить исключение
! Итак, друзья должны не забыть удалить
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
Таким образом, больше никаких исключений не будет!
Получение этой ошибки
kotlin.NotImplementedError: An operation is not implemented: not implemented
Я реализую прослушиватель кликов ImageButton
Требование: — Я хочу выполнить действие при нажатии кнопки изображения, но получаю указанную выше ошибку
Поправьте меня, а также, если есть какая-либо другая работа для реализации прослушивателя нажатия кнопки изображения, предоставьте его, спасибо
Вот класс Java fragment
class FragmentClass : Fragment(), View.OnClickListener {
override fun onClick(v: View?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
when (v?.id) {
R.id.back_icon -> {
Toast.makeText(activity, "back button pressed", Toast.LENGTH_SHORT).show()
activity.onBackPressed()
}
else -> {
}
}
}
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view: View = inflater!!.inflate(R.layout.fragment_class, container,
false)
val activity = getActivity()
var input_name = view.findViewById(R.id.input_name) as EditText
var tv_addbucket = view.findViewById(R.id.tv_addbucket) as TextView
val back_icon: ImageButton = view.findViewById(R.id.back_icon)
back_icon.setOnClickListener(this)
tv_addbucket.setOnClickListener(View.OnClickListener {
Toast.makeText(activity, input_name.text, Toast.LENGTH_SHORT).show()
})
return view;
}
}
а затем fragment_class. xml
<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout 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">
<RelativeLayout
android:id = "@+id/header"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:focusable = "true"
android:focusableInTouchMode = "true"
android:clickable = "true"
android:padding = "10dp">
<ImageButton
android:id = "@+id/back_icon"
android:layout_width = "40dp"
android:layout_height = "40dp"
android:background = "#0000"
android:focusable = "true"
android:focusableInTouchMode = "true"
android:clickable = "true"
android:src = "@drawable/back_icon" />
<TextView
android:id = "@+id/tv_header"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_centerHorizontal = "true"
android:text = "Add Bucket" />
</RelativeLayout>
<ScrollView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_below = "@+id/header"
android:fillViewport = "true">
<LinearLayout
android:layout_width = "fill_parent"
android:layout_height = "match_parent"
android:layout_marginTop = "?attr/actionBarSize"
android:orientation = "vertical"
android:paddingLeft = "20dp"
android:paddingRight = "20dp"
android:paddingTop = "60dp">
<android.support.design.widget.TextInputLayout
android:id = "@+id/input_layout_name"
android:layout_width = "match_parent"
android:layout_height = "wrap_content">
<EditText
android:id = "@+id/input_name"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:hint = "Bucket Name"
android:singleLine = "true" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id = "@+id/tv_addbucket"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "40dp"
android:background = "@drawable/blue_stroke_background"
android:gravity = "center"
android:padding = "15dp"
android:text = "Add"
android:textColor = "@color/white" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Перейти к ответу
Данный вопрос помечен как решенный
Ответы
3
TODO()
— это встроенная функция в Котлине. Он ВСЕГДА будет вызывать NotImplementedError. См. #Documentation: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-t-o-d-o.html
Если вы хотите просто отметить, что этот фрагмент кода все еще требует доработки, используйте // TODO
. Тогда отметка будет видна в разделе TODO, но не вызовет исключения.
Просто удалите TODO( ... )
из onClickListener:
override fun onClick(v: View?) {
// No TODO here
when (v?.id) {
...
}
}
TODO(...)
— это функция Kotlin, которая всегда выбрасывает NotImplementedError
. Если вы хотите пометить что-то с помощью TODO, но не генерировать исключение — просто используйте TODO с комментариями:
override fun onClick(v: View?) {
//TODO: implement later
when (v?.id) {
...
}
}
Я реализовал это
val extraTime = arrayListOf<String>("1 hour")
val extraTimeAdapter = CustomSpinDeliveryExtraTimeAdapter(context!!, R.layout
.simple_spinner_text_middle_down_arrow, extraTime)
spinCustomTime.adapter = extraTimeAdapter
spinCustomTime.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
После удаления задачи из этого кода ниже
spinCustomTime.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
}
}
решил мою проблему.
Также см. Ссылку на этот документ для уточнения
См. #Documentation: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-t-o-d-o.html