我不断收到此错误:预期出现错误:')',但似乎找不到问题

时间:2019-05-07 15:37:54

标签: java android

我对编程和编写任何应用程序甚至使用Java编写应用程序都是陌生的。我不断收到似乎无法修复的错误。感谢您提供任何解决此问题的帮助。我将代码粘贴到了错误所在的位置。

谢谢。

 Button Save;
 EditText edt1, edt2, edt3;
 int in;
 Float fl;
 String st;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //loading the default fragment
    loadFragment(new HomeFragment());

    //getting bottom navigation view and attaching the listener
    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(this);

    Save = (Button) findViewById(R.id.BtnSave);
    edt1 = (EditText) findViewById(R.id.editText1);
    edt2 = (EditText) findViewById(R.id.editText2);
    edt3 = (EditText) findViewById(R.id.editText3);

    // to Retrieve the Data from the SharedPref

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        int in1= prefs.getInt("in",0);
        edt1.setText(""+in1);

        float fl1 = prefs.getFloat("fl", 0);
        edt2.setText(""+fl1);

        String st1 = prefs.getString("st","");
        edt3.setText(""+st1);


    Save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            in = Integer.parseInt(edt1.getText().toString());
            fl = Float.parseFloat(edt2.getText().toString());
            st = edt3.getText().toString();

            // To save the data that is entered
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            SharedPreferences.Editor editor = prefs.edit();

            editor.putInt("in", in);
            editor.putFloat("fl", fl);
            editor.putString("st", st);
            editor.apply();
        }
    }
}
}

1 个答案:

答案 0 :(得分:1)

您在);之后错过了setOnClickListener

Save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            in = Integer.parseInt(edt1.getText().toString());
            fl = Float.parseFloat(edt2.getText().toString());
            st = edt3.getText().toString();

            // To save the data that is entered
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            SharedPreferences.Editor editor = prefs.edit();

            editor.putInt("in", in);
            editor.putFloat("fl", fl);
            editor.putString("st", st);
            editor.apply();
        }
    });