android - 尝试在空对象引用上调用虚拟方法“void com.facebook.marketing.ViewIndexer.unschedule()”
问题描述
由于我使用的是 Facebook Account Kit,所以我遇到了这种错误,我不知道如何处理它,请帮助我,伙计们。
E/AndroidRuntime:致命异常:主进程:in.co.ashclan.thunder,PID:29664 java.lang.RuntimeException:无法暂停活动 {in.co.ashclan.thunder/in.co.ashclan.thunder.ActivitySplash} :java.lang.NullPointerException:尝试在android.app的android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3830)的空对象引用上调用虚拟方法'void com.facebook.marketing.ViewIndexer.unschedule()' .ActivityThread.performPauseActivity(ActivityThread.java:3796) 在 android.app.ActivityThread.performPauseActivity(ActivityThread.java:3770) 在 android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3741) 在 android.app.ActivityThread。android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper. java:163) at android.app.ActivityThread.main(ActivityThread.java:6239) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit. java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) 原因:java.lang.NullPointerException:尝试调用虚拟方法'void com.facebook.marketing.ViewIndexer.unschedule() ' 在 com.facebook.marketing 的空对象引用上。CodelessActivityLifecycleTracker$1.onActivityPaused(CodelessActivityLifecycleTracker.java:129) 在 android.app.Application.dispatchActivityPaused(Application.java:229) 在 android.app.Activity.onPause(Activity.java:1654) 在 android.support.v4.app。 FragmentActivity.onPause(FragmentActivity.java:441) 在 android.app.Activity.performPause(Activity.java:7024) 在 android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1323) 在 android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread .java:3819) 在 android.app.ActivityThread.performPauseActivity(ActivityThread.java:3796) 在 android.app.ActivityThread.performPauseActivity(ActivityThread.java:3770) 在 android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3741) 在 android.app.ActivityThread.-wrap16(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538) 在 android .os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper.java:163) 在 android.app.ActivityThread.main(ActivityThread.java:6239) 在 java.lang.reflect。 Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) V/FA :活动暂停,时间:966233817handlePauseActivity(ActivityThread.java:3741) 在 android.app.ActivityThread.-wrap16(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538) 在 android.os.Handler.dispatchMessage(Handler. java:102) 在 android.os.Looper.loop(Looper.java:163) 在 android.app.ActivityThread.main(ActivityThread.java:6239) 在 java.lang.reflect.Method.invoke(Native Method) 在 com .android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) V/FA:活动暂停,时间:966233817handlePauseActivity(ActivityThread.java:3741) 在 android.app.ActivityThread.-wrap16(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538) 在 android.os.Handler.dispatchMessage(Handler. java:102) 在 android.os.Looper.loop(Looper.java:163) 在 android.app.ActivityThread.main(ActivityThread.java:6239) 在 java.lang.reflect.Method.invoke(Native Method) 在 com .android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) V/FA:活动暂停,时间:966233817android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper. java:163) at android.app.ActivityThread.main(ActivityThread.java:6239) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit. java:904) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) V/FA:活动暂停,时间:966233817android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper. java:163) at android.app.ActivityThread.main(ActivityThread.java:6239) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit. java:904) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) V/FA:活动暂停,时间:966233817102) 在 android.os.Looper.loop(Looper.java:163) 在 android.app.ActivityThread.main(ActivityThread.java:6239) 在 java.lang.reflect.Method.invoke(Native Method) 在 com.android .internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) V/FA:活动暂停,时间:966233817102) 在 android.os.Looper.loop(Looper.java:163) 在 android.app.ActivityThread.main(ActivityThread.java:6239) 在 java.lang.reflect.Method.invoke(Native Method) 在 com.android .internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) V/FA:活动暂停,时间:966233817java:794) V/FA:活动暂停,时间:966233817java:794) V/FA:活动暂停,时间:966233817
这是我的代码
public class ParticipantsLogin extends AppCompatActivity implements View.OnClickListener{
FButton btn_facebook,btn_Gmail,btn_submit;
FirebaseDatabase database;
DatabaseReference table_participant ;
FirebaseStorage storage;
Context mContext;
DatabaseReference table_user;
//Get GMail Data from login Account
public String personName,personFirstName,personLastName,personEmail,personId;
Uri personPhoto ;
//Root Layout
LinearLayout linearLayout;
//Participant Pojo
ParticipantModel participantModel;
//FireBase to Facebook
private static final int RC_SIGN_IN = 9001;
private static final String TAG = "GoogleSignIn";
//FireBase to Google
private FirebaseAuth mAuth;
GoogleSignInClient mGoogleSignInClient;
public static final int REQUEST_CODE = 7171;
MaterialEditText edtUserName,edtPassword;
String phone,pass;
//Alert Dialog View
MaterialEditText edtMobileNo;
RadioButton rd_male,rd_female;
//Upload Images
Uri saveuri;
StorageReference storageReference ;
@Override
protected void onCreate(Bundle savedInstanceState)
{
FacebookSdk.sdkInitialize(getApplicationContext());
AccountKit.initialize(this);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_participants_login);
mInit();
btn_Gmail.setOnClickListener(this);
btn_facebook.setOnClickListener(this);
btn_submit.setOnClickListener(this);
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
//Initialisation
private void mInit()
{
mContext = ParticipantsLogin.this;
btn_facebook = (FButton)findViewById(R.id.btn_facebook);
btn_Gmail = (FButton)findViewById(R.id.btn_Gmail);
//InIt FireBase
database = FirebaseDatabase.getInstance();
table_participant = database.getReference("Participant"); //Linked to Participant table
mAuth = FirebaseAuth.getInstance();
storage = FirebaseStorage.getInstance();
storageReference = storage.getReference();
//Init ROOT LAYOUT
linearLayout = (LinearLayout)findViewById(R.id.root_layout);
participantModel = new ParticipantModel();
//Submit Button
btn_submit = (FButton)findViewById(R.id.btn_submit);
edtUserName = (MaterialEditText)findViewById(R.id.edt_User_id);
edtPassword = (MaterialEditText)findViewById(R.id.edt_User_password);
}
//OnclickListner
@Override
public void onClick(View view)
{
switch (view.getId())
{
case R.id.btn_facebook:
startFacebookLogin();
break;
case R.id.btn_Gmail:
startGmailLogin();
break;
case R.id.btn_submit:
//Save username and password
phone = edtUserName.getText().toString();
pass = edtPassword.getText().toString();
if(edtUserName.getText().length()==0)
{
edtUserName.setError("Please Enter Your Mobile No");
} else if (edtPassword.getText().length()==0) {
edtPassword.setError("Please enter correct password");
}else {
login(phone, pass);
}
break;
}
}
//Methods
private void startFacebookLogin()
{
Intent intent = new Intent(ParticipantsLogin.this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(LoginType.PHONE,
AccountKitActivity.ResponseType.TOKEN);
intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,configurationBuilder.build());
startActivityForResult(intent,REQUEST_CODE);
}
private void startGmailLogin()
{
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
try{
//Activity result set for facebook login
if(requestCode==REQUEST_CODE)
{
AccountKitLoginResult result = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
if(result.getError()!=null)
{
Toast.makeText(this, ""+result.getError().getErrorType().getMessage(), Toast.LENGTH_SHORT).show();
return;
}else if(result.wasCancelled())
{
Toast.makeText(this, "Canceled", Toast.LENGTH_SHORT).show();
return;
}
else
{
if(result.getAccessToken() != null)
{
//Show Dialog
final AlertDialog watingDialog = new SpotsDialog(this);
watingDialog.show();
watingDialog.setMessage("Please Wait");
watingDialog.setCancelable(false);
//get Current Phone
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(Account account) {
String phone = account.getPhoneNumber().toString();
final String userphone = phone.substring(3);
Log.e("fbno-->",userphone);
//Check if User Exist on Firebase if not then add it
table_participant.orderByKey().equalTo(userphone)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(!dataSnapshot.child(userphone).exists())//if User not Exist
{
Intent intent = new Intent(ParticipantsLogin.this,RegistrationActivity.class);
intent.putExtra("mobilno",userphone);
startActivity(intent);
watingDialog.dismiss();
finish();
}else //if User Exist
{
startActivity(new Intent(ParticipantsLogin.this, Activity_DashBoard2.class));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void onError(AccountKitError accountKitError) {
Toast.makeText(ParticipantsLogin.this, ""+accountKitError.getErrorType().getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
}catch (Exception e)
{
Log.e("-->FbError",e.toString());
}
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
// ...
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct)
{
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
//Show Dialog
final AlertDialog watingDialog = new SpotsDialog(this);
watingDialog.show();
watingDialog.setMessage("Please Wait");
watingDialog.setCancelable(false);
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
//showFireBaseDialog();
watingDialog.dismiss();
//If user is not registred then register it
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
// Snackbar.make(findViewById(R.id.main_layout), "Authentication Failed.", Snackbar.LENGTH_SHORT).show();
updateUI(null);
}
}
});
}
//User Login
private void login(final String phone, final String pass)
{
try
{
Log.d("-->",phone +" "+pass);
if (util.isConnectedToInterNet(getBaseContext())) {
final ProgressDialog mDialog = new ProgressDialog(ParticipantsLogin.this);
mDialog.setMessage("Please Wait.....");
mDialog.setCancelable(false);
mDialog.show();
table_participant.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Check if User doesnt exist in database
if (dataSnapshot.child(phone).exists()) {
//mDialog.dismiss();
//get User Values
Log.d("-->123",dataSnapshot.toString());
ParticipantModel user = dataSnapshot.child(phone).getValue(ParticipantModel.class);
user.setMobile(phone);
Log.d("PoJo-->",user.toString());
if (user.getFirstname().equals(pass)) {
Toast.makeText(getApplicationContext(),"Successful",Toast.LENGTH_LONG).show();
startActivity(new Intent(mContext,Activity_DashBoard2.class));
PreferenceUtil.setSignIn(mContext,true);
PreferenceUtil.setMobileNo(mContext,phone);
PreferenceUtil.setPass(mContext,pass);
mDialog.dismiss();
finish();
} else {
mDialog.dismiss();
Toast.makeText(getApplicationContext(), "Wrong Password", Toast.LENGTH_LONG).show();
}
} else {
mDialog.dismiss();
Toast.makeText(getApplicationContext(), "User Doesnt Exist", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
Toast.makeText(ParticipantsLogin.this, "Please Check Your Internet Connection!", Toast.LENGTH_SHORT).show();
}
}catch (Exception e)
{
Log.e("-->",e.toString());
Toast.makeText(mContext, "Something went Wrong!", Toast.LENGTH_SHORT).show();
}
}
private void updateUI(FirebaseUser user)
{
if (user != null) {
// User is signed in
GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(getApplicationContext());
if (acct != null) {
personName = acct.getDisplayName();
personFirstName = acct.getGivenName();
personLastName = acct.getFamilyName();
personEmail = acct.getEmail();
personId = acct.getId();
personPhoto = acct.getPhotoUrl();
/* Toast.makeText(ParticipantsLogin.this, "" + personName + "\n" +
personFirstName + "\n" +
personLastName + "\n" +
personEmail + "\n", Toast.LENGTH_LONG).show();*/
PreferenceUtil.setSignIn(ParticipantsLogin.this,true);
} else {
// No user is signed in
}
//Show Dialog
android.support.v7.app.AlertDialog.Builder alertDialog = new android.support.v7.app.AlertDialog.Builder(ParticipantsLogin.this);
alertDialog.setTitle("One More Step... ");
alertDialog.setMessage("Please Enter Your Registred Mobile");
LayoutInflater layoutInflater = this.getLayoutInflater();
View view = layoutInflater.inflate(R.layout.custom_mobileno_dialog, null);
edtMobileNo = (MaterialEditText) view.findViewById(R.id.edt_gm_MobileNo);
alertDialog.setView(view);
alertDialog.setIcon(R.drawable.ic_person);
//Set Buttons
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final String phone = edtMobileNo.getText().toString();
final AlertDialog watingDialog = new SpotsDialog(ParticipantsLogin.this);
watingDialog.show();
watingDialog.setMessage("Please Wait");
watingDialog.setCancelable(false);
//Check if User Exist on Firebase if not then add it
table_participant.orderByKey().equalTo(phone)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!dataSnapshot.child(phone).exists())//if User not Exist
{
Intent intent = new Intent(ParticipantsLogin.this, RegistrationActivity.class);
intent.putExtra("email", personEmail);
intent.putExtra("firstname", personFirstName);
intent.putExtra("lastname", personLastName);
intent.putExtra("mobilno", phone);
PreferenceUtil.setMobileNo(mContext,phone);
PreferenceUtil.setEmailid(mContext,personEmail);
PreferenceUtil.setLastname(mContext,personLastName);
PreferenceUtil.setFirstname(mContext,personFirstName);
PreferenceUtil.setPass(mContext,personFirstName);
startActivity(intent);
watingDialog.dismiss();
finish();
} else//if User Exist
{
table_participant.child(phone)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ParticipantModel localUser = dataSnapshot.getValue(ParticipantModel.class);
startActivity(new Intent(ParticipantsLogin.this, Activity_DashBoard2.class));
util.currentParticipant = localUser;
PreferenceUtil.setMobileNo(mContext,phone);
PreferenceUtil.setEmailid(mContext,personEmail);
PreferenceUtil.setLastname(mContext,personLastName);
PreferenceUtil.setFirstname(mContext,personFirstName);
PreferenceUtil.setPass(mContext,personFirstName);
watingDialog.dismiss();
finish();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
//Check User VAlidataions
public boolean utilsCheck()
{
boolean cancel = false;
View focusView = null;
if (TextUtils.isEmpty(edtUserName.getText())){
edtUserName.setError("Please enter first Name");
focusView=edtUserName;
cancel=true;
}
if (TextUtils.isEmpty(edtPassword.getText())){
edtPassword.setError("Please enter Password");
focusView=edtPassword;
cancel=true;
}
return cancel;
}
}
公共类 SplashScreen 扩展 AppCompatActivity {
Context mcontext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
try {
if (PreferenceUtil.getSignIn(this)) {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreen.this, Activity_DashBoard2.class);
startActivity(intent);
finish();
}
}, 7000);
} else {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreen.this, ParticipantsLogin.class);
startActivity(intent);
finish();
}
}, 7000);
}
}catch (Exception e)
{
Log.e("-->splashexp",e.toString());
}
}
private void login(final String phone, final String pass) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference table_user = database.getReference("Participant");
Log.d("-->",phone +" "+pass);
if (util.isConnectedToInterNet(getBaseContext())) {
final ProgressDialog mDialog = new ProgressDialog(mcontext);
mDialog.setMessage("Please Wait.....");
mDialog.show();
table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Check if User doesnt exist in database
if (dataSnapshot.child(phone).exists()) {
//mDialog.dismiss();
//get User Values
Log.d("-->123",dataSnapshot.toString());
ParticipantModel user = dataSnapshot.child(phone).getValue(ParticipantModel.class);
user.setMobile(phone);
Log.d("PoJo-->",user.toString());
if (user.getFirstname().equals(pass)) {
//Toast.makeText(getApplicationContext(),"Successful",Toast.LENGTH_LONG).show();
startActivity(new Intent(mcontext, DashBoard.class));
util.currentParticipant = user;
finish();
} else {
mDialog.dismiss();
Toast.makeText(getApplicationContext(), "Wrong Password", Toast.LENGTH_LONG).show();
}
} else {
mDialog.dismiss();
Toast.makeText(getApplicationContext(), "User Doesnt Exist", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
Toast.makeText(mcontext, "Please Check Your Internet Connection!", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
}
解决方案
升级facebook-android-sdk
对我有用:
implementation com.facebook.android:facebook-android:5.1.1
我也不鼓励人们使用通配符格式,例如
implementation com.facebook.android:facebook-android-sdk:[4:5)
尽管 facebook 在他们的网站上推荐它,因为如果最新版本的库发生更改并破坏某些东西,它可能会导致不可预测的构建。
推荐阅读
- accessibility - 在 IE11 中按下回车键后,Jaws 不允许在文本框中输入值
- java - 如何使用 Java 泛型方法?
- grafana - 为什么 Grafana 不适用于 32 位 Windows 机器
- gis - 从 GRASS 7.2.2 切换到 7.6.1 后,v.overlay 错误“尚不支持与点的交叉点”
- typescript - 如何将一个枚举映射到打字稿中的另一个枚举?
- python - 项目的python设置 - 循环导入/依赖注入
- python - 无法在 VS Code 的输出窗格中使用正确的 python 解释器
- laravel - laravel 护照持有人令牌不起作用
- geode - Apache Geode 区域与缓存
- java - 如何获取在 RestTemplate springBoot 应用程序中通过 url 传递的所有查询参数的列表?