kp7742 / WAAutoResponder-NoRoot

WhatsApp Chat AutoResponder Bot
GNU General Public License v3.0
31 stars 14 forks source link

NullPointerException #2

Open ShaubertIlya opened 4 years ago

ShaubertIlya commented 4 years ago

Hi. I've tried your code and it works fine except of weird issue that appears sometimes.

java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at com.kmods.waautoresponder.NotificationReceiver.sendMsg(NotificationReceiver.java:175) at com.kmods.waautoresponder.NotificationReceiver.access$100(NotificationReceiver.java:27) at com.kmods.waautoresponder.NotificationReceiver$1.run(NotificationReceiver.java:73) at java.lang.Thread.run(Thread.java:764)

It sends me here - Objects.requireNonNull(replyAction(notification)).actionIntent.send(this, 0, localIntent);

Program works time after time. 2,3,4... messages can work fine and then the error and no respond.

What could be a problem?

sivakumarswaminthan commented 4 years ago

@ShaubertIlya - I am facing the same issue? Any luck you happened to fix this

kevin4dhd commented 4 years ago

Logre arreglarlo poniéndolo Handler con un postdelayed Mi código:

new Handler().postDelayed(new Runnable() { @Override public void run() { try{ notification = sbn.getNotification();//Latest Notification of WhatsApp if(notification != null){ bundle = notification.extras; //logBundle(bundle); remoteInputs = getRemoteInputs(notification); if(remoteInputs != null && remoteInputs.size() > 0){ Object isGroupConversation = bundle.get("android.isGroupConversation"); String conversationTitle = bundle.getString("android.conversationTitle");

                            if(isGroupConversation != null){
                                boolean isGroup = (((boolean) isGroupConversation) && (conversationTitle != null));//Group Params
                                Object title = bundle.get("android.title");//Chat Title
                                Object text = bundle.get("android.text");//Chat Text

                                if(title != null && text instanceof String) {
                                    String texto = (String) text;
                                    //Common Replies
                                    if (texto.contains("/comandos")) {
                                        sendMsg("Prueba 1 V2.0");
                                    } else if (texto.contains("/test")) {
                                        sendMsg("Test V2");
                                    } else if (texto.contains("/suma")) {
                                        sendMsg("Sumando...");
                                    }else if(texto.contains("/math")){
                                        String resultado = getResultado(texto);
                                        if(resultado!=null){
                                            sendMsg(resultado);
                                        }else{
                                            System.out.println("ERROR: NULL");
                                        }
                                    }
                                    //Group Specific Replies
                                    if(isGroup) {
                                        String[] title_split = parseTitle(String.valueOf(title));
                                        String group_name = title_split[0];
                                        String sender = title_split[(title_split.length - 1)];

                                        if(text.equals("@warnings")){
                                            sendMsg("Hello " +
                                                    sender +
                                                    " :-\n\n" +
                                                    "Sorry But This Feature is Still Under Construction!");
                                        }

                                        //for Comp162 and 16-Comp Group
                                        if(String.valueOf(title).contains("Comp162") || String.valueOf(title).contains("16-Comp")) {
                                            if (text.equals("@help")) {
                                                sendMsg("*Comp162 Group Commands* :-\n" +
                                                        "\n" +
                                                        "@goodmorning and @goodnight - to greet group Members.");
                                            } else if(text.equals("@goodmorning")){
                                                sendMsg("Good Morning All!");
                                            } else if(text.equals("@goodnight")){
                                                sendMsg("Good Night All!");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e){
                    notification = null;
                    e.printStackTrace();
                }
            }
        },1000);