尝试调用虚拟方法'java.lang.String com.turismo.usuario.uber.Model.User.getAvatarUrl()

时间:2019-05-31 15:34:12

标签: java android nullpointerexception

我正在尝试使用Facebook帐户套件登录,但它显示了一个错误。我已将登录名更改为Facebook帐户工具包。

错误是:尝试调用虚拟方法'java.lang.String com.turismo.usuario.uber.Model.User.getAvatarUrl()

中未收到AvatarUrl红线
txtName.setText(Common.currentUser.getName());
 //But with Avatar , we just check it with null or empty
        if (Common.currentUser.getAvatarUrl() != null
                && !TextUtils.isEmpty(Common.currentUser.getAvatarUrl())) {
            Picasso.with(this)
                    .load(Common.currentUser.getAvatarUrl())
                    .into(imageAvatar);
        }

这是我的DriverActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_driver_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //Init Firebase Storage
    firebaseStorage = FirebaseStorage.getInstance();
    storageReference = firebaseStorage.getReference();

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View navigationHeaderView = navigationView.getHeaderView(0);
    TextView txtName = (TextView)navigationHeaderView.findViewById(R.id.txtDriverName);
    CircleImageView imageAvatar = (CircleImageView)navigationHeaderView.findViewById(R.id.image_avatar);

    //We can access from Common.currentUser because in MainActivity, after login , we have set this data
    txtName.setText(Common.currentUser.getName());
    //But with Avatar , we just check it with null or empty
    if (Common.currentUser.getAvatarUrl() != null
            && !TextUtils.isEmpty(Common.currentUser.getAvatarUrl())) {
        Picasso.with(this)
                .load(Common.currentUser.getAvatarUrl())
                .into(imageAvatar);
    }

    //Paste Here
    handler = new Handler();
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    //Presense System
    AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
        @Override
        public void onSuccess(Account account) {
            onlineRef = FirebaseDatabase.getInstance().getReference(".info/connected");
            currentUserRef = FirebaseDatabase.getInstance().getReference(Common.driver_tbl)
                    .child(account.getId());
            onlineRef.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    //We will remove value from Driver tbl when driver disconnected
                    currentUserRef.onDisconnect().removeValue();
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }

        @Override
        public void onError(AccountKitError accountKitError) {

        }
    });

    //Init View
    location_switch = (MaterialAnimatedSwitch)findViewById(R.id.location_switch);
    location_switch.setOnCheckedChangeListener(new MaterialAnimatedSwitch.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(boolean isOnline) {
            if (isOnline)
            {
                FirebaseDatabase.getInstance().goOnline();  // set connected when switch to on

                startLocationUpdates();
                displayLocation();
                Snackbar.make(mapFragment.getView(),"Estás en Línea",Snackbar.LENGTH_SHORT)
                        .show();
            }
            else
            {
                FirebaseDatabase.getInstance().goOffline(); //Set disconnected when switch to off

                stopLocationUpdates();
                mCurrent.remove();
                mMap.clear();
                if (handler != null)
                    handler.removeCallbacks(drawPathRunnable);
                Snackbar.make(mapFragment.getView(),"Estás desconectado",Snackbar.LENGTH_SHORT)
                        .show();
            }
        }
    });

    polyLineList = new ArrayList<>();
    //Places API
    typeFilter = new AutocompleteFilter.Builder()
            .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
            .setTypeFilter(3)
            .build();



    //Geo Fire
    drivers = FirebaseDatabase.getInstance().getReference(Common.driver_tbl);
    geoFire = new GeoFire(drivers);

    setUpLocation();

    mService = Common.getGoogleAPI();

    updateFirebaseToken();
}

private void updateFirebaseToken() {



    AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
        @Override
        public void onSuccess(Account account) {
            FirebaseDatabase db = FirebaseDatabase.getInstance();
            DatabaseReference tokens = db.getReference(Common.token_tbl);
            Token token = new Token(FirebaseInstanceId.getInstance().getToken());
            tokens.child(account.getId())
                    .setValue(token);
        }

        @Override
        public void onError(AccountKitError accountKitError) {

        }
    });
}

0 个答案:

没有答案