I am learning develop extensions.
but when i try it’s returning “null”
what is my wrong. Does anyone help me?
package com.ruwis.webslapper;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.errors.YailRuntimeError;
import com.google.appinventor.components.runtime.util.YailList;
public class WebSlapper extends AndroidNonvisibleComponent {
public WebSlapper(ComponentContainer container) {
super(container.$form());
}
@SimpleFunction()
public List<String> VeriCek(String url, String css) {
try {
Connection connect = Jsoup.connect(url).userAgent("Mozilla/5.0");
Document liste = connect.get();
Elements secilen = liste.select(css);
return YailList.makeList(secilen);
}
catch(Exception e) {
return null;
}
}
}
You can’t return null, instead return an empty list.
so do you see any other error?
There’s no other error, except that you should return an empty list instead of null. App Inventor doesn’t respond well to null, although they should definitely add that.
1 Like
I set it as empty list but it returns empty list every time. I couldn’t find my mistake
vknow360
(Sunny Gupta)
July 18, 2021, 12:41am
#6
Jsoup does not parse html synchronously so you need to check whether document is null or not on a regular interval.
This thing is missing in HtmlUtils extension too.
2 Likes
hey this post is mine. I solved the problem as in this example.
new Thread() {
public void run() {
WebSlapper.this.activity.runOnUiThread(new Runnable() {
public void run() {
try {
Document doc = Jsoup.connect(url).userAgent("Mozilla/5.0").get();
Elements elements = doc.select(cssSelector);
WebSlapped(elements);
}
catch(Exception exception) {
ErrorOccurred(exception.getMessage());
}
}
});
}
}.start();
@Peter will one day find out you have two accounts
What’s wrong with having 2 accounts?
Peter
(Moderator)
July 19, 2021, 12:58am
#10
Only one is allowed on the community. Which one should i delete?
1 Like
Peter
(Moderator)
July 19, 2021, 4:14am
#12
OmerGundogar:
it
It means this one or the other one?