标签: illegalstateexception

Java:`iterator.remove` 抛出 IllegalStateException

我有一个iteratorinside thread,我正在尝试删除重复的记录。

 Runnable readingThread = new Runnable() {
        @Override
        public void run() {

            Iterator<Demand> iterator = null;
            for (iterator = demandListFromFile.iterator(); iterator.hasNext();) {
                Demand demand = iterator.next();

                /**
                 * Find and assign the Item ID
                 */
                if (itemListHashMap.containsValue(demand.getItem().getItemName())) {
                    demand.getItem().setIditem(itemListHashMapReversed.get(demand.getItem().getItemName()));

                } else {
                    unavailableItemsList.add(demand.getItem().getItemName());
                }


                /**
                 * Find and remove duplicate records
                 */
                for (Map.Entry<Date, String> entry : demandListHashMap.entries()) {

                    if (demand.getDueDate().equals(entry.getKey()) && demand.getItem().getItemName().equals(entry.getValue())) {

                        iterator.remove();
                    }

                }

            }

        }
Run Code Online (Sandbox Code Playgroud)

删除几个项目后,iterator.remove抛出以下异常

Exception in thread "Thread-0" …
Run Code Online (Sandbox Code Playgroud)

java iterator illegalstateexception

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

使用Intent显示URL

我在运行时收到错误.单击按钮时发生Logcat错误.

java.lang.IllegalStateException: Could not find a method onClickWebBrowser(View) in the activity class com.steph.intents.IntentActivity for onClick handler on view class android.widget.Button with id 'btn_webbrowser'

堆栈跟踪:

 E/AndroidRuntime(1931): FATAL EXCEPTION: main
 E/AndroidRuntime(1931): Process: com.steph.intents, PID: 1931
 E/AndroidRuntime(1931): java.lang.IllegalStateException: Could not find a method onClickWebBrowser(View) in the activity class com.steph.intents.IntentActivity for onClick handler on view class android.widget.Button with id 'btn_webbrowser'
 E/AndroidRuntime(1931):    at android.view.View$1.onClick(View.java:3810)
 E/AndroidRuntime(1931):    at android.view.View.performClick(View.java:4438)
 E/AndroidRuntime(1931):    at android.view.View$PerformClick.run(View.java:18422)
 E/AndroidRuntime(1931):    at android.os.Handler.handleCallback(Handler.java:733)
 E/AndroidRuntime(1931):    at android.os.Handler.dispatchMessage(Handler.java:95)
 E/AndroidRuntime(1931):    at android.os.Looper.loop(Looper.java:136)
 E/AndroidRuntime(1931):    at android.app.ActivityThread.main(ActivityThread.java:5017)
 E/AndroidRuntime(1931):    at java.lang.reflect.Method.invokeNative(Native …
Run Code Online (Sandbox Code Playgroud)

android android-intent illegalstateexception

-1
推荐指数
1
解决办法
254
查看次数

onClick方法仅适用于MainActivity

我有一个ImageButton,我想在我的应用程序的某个Fragment类中使用它.但是当我在我的片段类中使用它时,应用程序崩溃了.但我可以在我的MainActivity中使用它而不会崩溃.我怎样才能解决这个问题?

这是我在我的片段类中使用的代码

public void showPopup(View v) {
        PopupMenu popup = new PopupMenu(activity, v);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.song_popup, popup.getMenu());
        popup.show();

    }
Run Code Online (Sandbox Code Playgroud)

这会导致应用程序崩溃.但是当我在MainActivity中使用它时(在mainactivity中,"activity"被this.getApplicationContext替换)它可以工作.

我的按钮xml

<ImageButton
                android:id="@+id/popUp"
                android:layout_width="20dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_marginRight="2dp"
                android:background="@null"
                android:src="@drawable/abc_ic_menu_moreoverflow_mtrl_alpha"
                android:onClick="showPopup" />
Run Code Online (Sandbox Code Playgroud)

logcat的

java.lang.IllegalStateException: Could not find a method showPopup(View) in the activity class com.fm.etunes.phone.MainActivity for onClick handler on view class android.widget.ImageButton with id 'popUp'
            at android.view.View$1.onClick(View.java:3814)
            at android.view.View.performClick(View.java:4442)
            at android.view.View$PerformClick.run(View.java:18473)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
            at …
Run Code Online (Sandbox Code Playgroud)

android illegalstateexception android-imagebutton

-5
推荐指数
1
解决办法
858
查看次数

无法在onClick处理程序的活动类com.example.alexander.mobileapp02.MainActivity中找到方法sendMessage(View)

我试图在互联网上找到答案,但我找不到它.我希望有人知道如何解决这个问题,因为否则我不能真正进一步使用这个试用版应用程序.

这是我遵循的教程和我最终的结果:http: //developer.android.com/training/basics/firstapp/starting-activity.html (在网站上按下之前的

我做了一个简单的应用程序,它进入主(第一个/主页)活动,然后输入你的名字并按下按钮.(见图).

当我按下按钮时,出现此错误:java.lang.IllegalStateException:无法在视图类android.widget.Button上的onClick处理程序的活动类com.example.alexander.mobileapp02.MainActivity中找到方法sendMessage(View).然后应用程序崩溃btw)

我只是要展示整个应用程序:

这里是完整的错误:

    Device driver API version: 23
    User space API version: 23
02-09 21:01:14.871  13128-13128/com.example.alexander.mobileapp02 E/? mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Fri Mar 21 13:52:50 KST 2014
02-09 21:01:14.956  13128-13128/com.example.alexander.mobileapp02 D/OpenGLRenderer? Enabling debug mode 0
02-09 21:01:22.961  13128-13139/com.example.alexander.mobileapp02 D/dalvikvm? GC_FOR_ALLOC freed 257K, 17% free 7921K/9456K, paused 21ms, total 21ms
02-09 21:01:39.271  13128-13128/com.example.alexander.mobileapp02 D/AndroidRuntime? Shutting down VM
02-09 21:01:39.271  13128-13128/com.example.alexander.mobileapp02 W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x41bd4c08)
02-09 21:01:39.281  13128-13128/com.example.alexander.mobileapp02 E/AndroidRuntime? FATAL EXCEPTION: main
    Process: …
Run Code Online (Sandbox Code Playgroud)

javascript java xml android illegalstateexception

-7
推荐指数
1
解决办法
2261
查看次数