I'm using below code to import a contact in my Telegram account.
Strange thing is the doRpcCall method runs without error (I suppose it means that the import has been taken place successfully), but in the next line of the code I'm getting IndexOutOfBound exception, which indicates that the successful imported contacts Vector is empty.
TLInputContact tlic = new TLInputContact(10, PhNo, Fname, Lname);
TLVector contacts = new TLVector<>();
contacts.add(tlic);
TLRequestContactsImportContacts importContacts = new TLRequestContactsImportContacts(contacts, true);
TLImportedContacts importedContacts = api.doRpcCall(importContacts);
System.out.println("Contact imported with ID:"+importedContacts.getUsers().get(0).getId());
TLAbsUser recipient=importedContacts.getUsers().get(0);
TLInputPeerContact peer = new TLInputPeerContact(recipient.getId());
TLRequestMessagesSendMessage sendMessageRequest = new TLRequestMessagesSendMessage(peer, "Test", rnd.nextInt());
TLAbsSentMessage sentMessage = api.doRpcCall(sendMessageRequest);
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at org.telegram.tl.TLVector.get(TLVector.java:158)
at org.telegram.bot.Application.importContacts(Application.java:58)
at org.telegram.bot.Application.main(Application.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
I'm using below code to import a contact in my Telegram account. Strange thing is the doRpcCall method runs without error (I suppose it means that the import has been taken place successfully), but in the next line of the code I'm getting IndexOutOfBound exception, which indicates that the successful imported contacts Vector is empty.
TLInputContact tlic = new TLInputContact(10, PhNo, Fname, Lname); TLVector contacts = new TLVector<>(); contacts.add(tlic); TLRequestContactsImportContacts importContacts = new TLRequestContactsImportContacts(contacts, true); TLImportedContacts importedContacts = api.doRpcCall(importContacts); System.out.println("Contact imported with ID:"+importedContacts.getUsers().get(0).getId()); TLAbsUser recipient=importedContacts.getUsers().get(0); TLInputPeerContact peer = new TLInputPeerContact(recipient.getId()); TLRequestMessagesSendMessage sendMessageRequest = new TLRequestMessagesSendMessage(peer, "Test", rnd.nextInt()); TLAbsSentMessage sentMessage = api.doRpcCall(sendMessageRequest);
Error: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at org.telegram.tl.TLVector.get(TLVector.java:158) at org.telegram.bot.Application.importContacts(Application.java:58) at org.telegram.bot.Application.main(Application.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)