Skip to content
Advertisement

When I open the file ActivityMainBindingImpl.java, there are some errors

I’m writing a program about basketball score. My program can run, but there are compilation errors in ActivityMainBindingImpl.java

error1: Cannot inherit from final ‘com.example.score.databinding.ActivityMainBinding’

error2: ‘ActivityMainBinding()’ has private access in ‘com.example.score.databinding.ActivityMainBinding’

score is my project name.

The file path is as follows: E:Scoreappbuildgeneratedap_generated_sourcesdebugoutcomexamplescoredatabindingActivityMainBindingImpl.java

If I don’t open the ActivityMainBindingImpl.java, there is no error.

Please give me some suggestions, I would appreciate it very much

This is MyViewModel.java

public class MyViewModel extends ViewModel {
    private MutableLiveData<Integer> aTeamScore;
    private MutableLiveData<Integer> bTeamScore;
    private int aBcak,bBack;
    public MutableLiveData<Integer> getaTeamScore() {
        if (aTeamScore == null){
            aTeamScore = new MutableLiveData<>();
            aTeamScore.setValue(0);
        }
        return aTeamScore;
    }
    public MutableLiveData<Integer> getbTeamScore() {
        if (bTeamScore == null){
            bTeamScore = new MutableLiveData<>();
            bTeamScore.setValue(0);
        }
        return bTeamScore;
    }
    public void aTeamAdd(int p){
        aBcak = aTeamScore.getValue();
        bBack = bTeamScore.getValue();
        aTeamScore.setValue(aTeamScore.getValue() + p);
    }
    public void bTeamAdd(int p){
        aBcak = aTeamScore.getValue();
        bBack = bTeamScore.getValue();
        bTeamScore.setValue(bTeamScore.getValue() +p );
    }

    public void reset(){
        aBcak = aTeamScore.getValue();
        bBack = bTeamScore.getValue();
        aTeamScore.setValue(0);
        bTeamScore.setValue(0);
    }
    public void undo(){
        aTeamScore.setValue(aBcak);
        bTeamScore.setValue(bBack);
    }
}

and this is MainActivity.java

package com.example.score;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import com.example.score.databinding.ActivityMainBinding;


public class MainActivity extends AppCompatActivity {
    MyViewModel myViewModel;
    ActivityMainBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
        myViewModel = new ViewModelProvider(this).get(MyViewModel.class);
        binding.setData(myViewModel);
        binding.setLifecycleOwner(this);
    }
}

Advertisement

Answer

It seems like you has implemented data binding in your project. Don’t worry about this In data binding this is autogenerated classes you don’t need to even touch it.

Just clean and rebuild project

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement