我做了一个应用程序,通过Facebook Graph获得一些Facebook帖子。一切都在我的手机上很好用(Cubot Note S && UMI Diamond),但当我尝试在我的手机LG K10(2017)的其他手机上打开应用程序时。我得到错误:java.lang.NullPointerException:
,我不知道为什么,因为在第一部手机上这个应用程序工作得很好。
java.lang.NullPointerException: Attempt to invoke virtual method
'java.util.List com.gireada.***.Posts2.getData()' on a null object reference
at com.gireada.***.MainActivity$3$1.onCompleted(MainActivity.java:153)
这是线
for (int i = 0; i < (variabila2.getPosts().getData().size()) - 1; i++)
每次当我尝试访问variabila2.getPosts()....
时,它都会给我这个错误:
前两款手机有6.0安卓和LG都有7.0,这可能是个问题吗?
我用这种方法制作了GraphCall
:
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
System.out.println(object);
Log.d("Profil ", object.toString());
globalObject.setCurentToken(AccessToken.getCurrentAccessToken());
String nome;
/*if (jObjResponse.has("name")) {
nome =
jObjResponse.getString("name");
globalObject.setNume(nome);
}
if (jObjResponse.has("id")) {
nome = jObjResponse.getString("id");
globalObject.setID_User(nome);
}*/
variabila2 = new Gson().fromJson(object.toString(), Variable2.class);
// System.out.println(variabila2.getPosts().toString());
// Log.d("Link ", variabila2.getPosts().getData().get(0).getLink());
for (int i = 0; i < (variabila2.getPosts().getData().size()) - 1; i++)
{
Log.d("Link ", variabila2.getPosts().getData().get(i).getLink());
if (variabila2.getPosts().getData().get(i).getCreated_time() != null)
globalObject.setCreated_global(variabila2.getPosts().getData().get(i).getCreated_time(), i);
else
globalObject.setCreated_global(null, i);
globalObject.setLink_global(variabila2.getPosts().getData().get(i).getLink(), i);
Log.d("Link Personal", variabila2.getPosts().getData().get(i).getLink());
if (variabila2.getPosts().getData().get(i).getFull_picture() != null)
globalObject.setLink_pictures(variabila2.getPosts().getData().get(i).getFull_picture(), i);
else
globalObject.setLink_pictures(null, i);
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,posts.limit(100){link,created_time,description,full_picture}");
request.setParameters(parameters);
request.executeAsync();
**Variable2 class**
public class Variable2
{
public String status;
public Feed feed;
Posts2 posts;
Picture picture;
public Variable2(Posts2 posts2) {
this.posts = posts2;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Feed getFeed() {
return feed;
}
public void setFeed(Feed feed) {
this.feed = feed;
}
public Posts2 getPosts() {
return posts;
}
public void setPosts(Posts2 posts) {
this.posts = posts;
}
public Picture getPicture() {
return picture;
}
public void setPicture(Picture picture) {
this.picture = picture;
}
}
**Post2 class**
public class Posts2 {
public List<Item2> data;
public Posts2(List<Item2> data) {
this.data = data;
}
public List<Item2> getData() {
return data;
}
public void setData(List<Item2> data) {
this.data = data;
}
}
**Item2 class**
public class Item2 {
public String link;
public String created_time;
public String full_picture;
public String description;
public String id;
public Item2(String link, String created_time, String description, String full_picture, String id) {
this.link = link;
this.created_time = created_time;
this.description = description;
this.full_picture = full_picture;
this.id = id;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getCreated_time() {
return created_time;
}
public void setCreated_time(String created_time) {
this.created_time = created_time;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFull_picture() {
return full_picture;
}
public void setFull_picture(String full_picture) {
this.full_picture = full_picture;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
这适用于我的第一部手机,但在这款手机上(可能在其他手机上)它不起作用。
如果你对这个问题有所了解,请帮助我。
我找到了答案。我没有把所有权限都放在登录按钮上。
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("user_posts", "public_profile", "email"));
感谢你的帮助。这就是我只获得少量数据的原因。
{"id":"2016399981939546","name":"Grigore Saveluc Rodica"}