从Firebase删除数据,提供“错误身份验证”错误

时间:2017-11-20 11:46:04

标签: android firebase android-intent firebase-realtime-database nullpointerexception

在博客应用中,我有两个活动Feed和单个帖子activity。 Feed活动会显示所有帖子,当用户点击其在一个帖子活动中打开的任何帖子时。

在单一帖子活动中,我有菜单提供编辑和删除帖子的选项。 在删除时,应该删除帖子并且意图应该让用户提供活动,但会发生什么,帖子被删除但意图没有执行,它显示下面给出的错误。

以下是我在菜单选项

中编写的代码
@Override
// Action on selecting the menu
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.action_edit) {

        // Add code to edit the post

    } else if (item.getItemId() == R.id.action_delete) {
   // Condition to test if the user who is deleting  the post is the same who posted it 
    if (PostUserName.getText().toString().equals(userName)) {

          // postkey is parent, which contains data of that single post
           dbref.child(postKey).removeValue();
           Intent toFeed = new Intent(SinglePostActivity.this, 
           FeedActivity.class);
           startActivity(toFeed);

        } else {

            Toast.makeText(this, "Can't delete", Toast.LENGTH_SHORT).show();
        }
    }

    return super.onOptionsItemSelected(item);
}

显示错误

  

11-20 16:20:48.808 1960-1979 /? E / Auth:[GoogleAccountDataServiceImpl] getToken() - > BAD_AUTHENTICATION。帐户:,App:com.android.vending,服务:androidmarket   edx:没有万岁证书。                                              at edy.b(:com.google.android.gms@11518470:10)                                              at edy.a(:com.google.android.gms@11518470:50)                                              在ecl.a(:com.google.android.gms@11518470:50)                                              在flk.a(:com.google.android.gms@11518470:8)                                              at flk.a(:com.google.android.gms@11518470:4)                                              在fkj.a(:com.google.android.gms@11518470:2)                                              at fkh.a(:com.google.android.gms@11518470:17)                                              at fkh.a(:com.google.android.gms@11518470:6)                                              在bsr.a(:com.google.android.gms@11518470:203)                                              在bsr.a(:com.google.android.gms@11518470:61)                                              在dzj.a(:com.google.android.gms@11518470:6)                                              at dzi.a(:com.google.android.gms@11518470:2)                                              at dzi.e(:com.google.android.gms@11518470:6)                                              在dzh.a(:com.google.android.gms@11518470:1)                                              at eax.getAuthToken(:com.google.android.gms@11518470:7)                                              在android.accounts.AbstractAccountAuthenticator $ Transport.getAuthToken(AbstractAccountAuthenticator.java:244)                                              在android.accounts.IAccountAuthenticator $ Stub.onTransact(IAccountAuthenticator.java:113)                                              在android.os.Binder.transact(Binder.java:499)                                              at buy.onTransact(:com.google.android.gms@11518470:3)                                              在android.os.Binder.execTransact(Binder.java:565)

已更新

通过从模拟器中删除我的帐户信息然后重新添加,然后通过更新Google Play服务和谷歌播放来解决问题。

但是,现在在第125行获得空指针异常,可能是因为单个帖子已被删除,现在单个帖子活动无法显示。我知道这是非常基本的,但我是编码的新手,不知道如何解决它。 这里是代码

 String postUserName = (String) dataSnapshot.child("userId").getValue();
 String postTitle = (String) dataSnapshot.child("title").getValue();
 String postDesc = (String) dataSnapshot.child("desc").getValue();
 String postImage = (String) dataSnapshot.child("image").getValue();

 // line 125, which showed error.
//  and I would also like to know why the above String did not show the same error

 long postupVoteCount = (long) dataSnapshot.child("upVote").getValue();
 int upVotes = (int) postupVoteCount;
 long postDownVoteCount = (long) dataSnapshot.child("downVote").getValue();
 int downVotes = (int) postDownVoteCount;

 PostUserName.setText(postUserName);
 PostTitle.setText(postTitle);
 PostDesc.setText(postDesc);
 PostUpVoteCount.setText(Integer.toString(upVotes));
 PostDownVoteCount.setText(Integer.toString(downVotes));

请帮助。

0 个答案:

没有答案