Ошибка: этот класс должен предоставлять конструктор по умолчанию (конструктор publi c без аргументов) при создании подписанных файлов APK - PullRequest
0 голосов
/ 07 января 2020

У меня есть файл java, который служит общими настройками для выполнения сеанса пользователя. Все отлично работало при отладке, но появляется ошибка при попытке создать подписанный APK. ошибка:

Этот класс должен предоставлять конструктор по умолчанию (конструктор publi c без аргументов)

Который указывает на эту часть:

 public UserSessionManager(Context context){
        super();
        this._context = context;
        pref = _context.getSharedPreferences(PREFER_NAME, PRIVATE_MODE);
        editor = pref.edit();
    }

это весь мой код:

package com.example.myapplication;

import java.util.HashMap;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class UserSessionManager {

    // Shared Preferences reference
    SharedPreferences pref;

    // Editor reference for Shared preferences
    Editor editor;

    // Context
    Context _context;

    // Shared pref mode
    int PRIVATE_MODE = 0;

    // Sharedpref file name
    private static final String PREFER_NAME = "AndroidExamplePref";

    // All Shared Preferences Keys
    private static final String IS_USER_LOGIN = "IsUserLoggedIn";

    // User name (make variable public to access from outside)
    public static final String KEY_PF = "pfno";

    // Email address (make variable public to access from outside)
    public static final String KEY_EMAIL = "password";

    public static final String KEY_NAME = "name";
    public static final String KEY_LEVEL = "level";

    public static final String KEY_MO = "MO";
    public static final String KEY_Machine = "Machine";
    public static final String KEY_Task = "Task";
    public static final String KEY_PFOPT = "PFopt";
    public static final String KEY_MATERIAL = "Material";
    // Constructor
    public UserSessionManager(Context context){
        super();
        this._context = context;
        pref = _context.getSharedPreferences(PREFER_NAME, PRIVATE_MODE);
        editor = pref.edit();
    }

    //Create login session
    public void createUserLoginSession(String pfno, String password, String name, String level){
        // Storing login value as TRUE
        editor.putBoolean(IS_USER_LOGIN, true);

        // Storing name in pref
        editor.putString(KEY_PF, pfno);

        editor.putString(KEY_NAME, name);
        editor.putString(KEY_LEVEL, level);

        // Storing email in pref
        editor.putString(KEY_EMAIL, password);

        // commit changes
        editor.commit();
    }
    public void HoldNewMODetails(String mo, String task, String machine, String material, String PFno){
        editor.putString(KEY_MO, mo);
        editor.putString(KEY_Machine, machine);
        editor.putString(KEY_MATERIAL, material);
        editor.putString(KEY_Task, task);
        editor.putString(KEY_PFOPT, PFno);

        editor.commit();
    }
    /**
     * Check login method will check user login status
     * If false it will redirect user to login page
     * Else do anything
     * */
    public boolean checkLogin(){
        // Check login status
        if(!this.isUserLoggedIn()){

            // user is not logged in redirect him to Login Activity
            Intent i = new Intent(_context, MainActivity.class);

            // Closing all the Activities from stack
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            // Add new Flag to start new Activity
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            // Staring Login Activity
            _context.startActivity(i);

            return true;
        }
        return false;
    }



    /**
     * Get stored session data
     * */
    public HashMap<String, String> getUserDetails(){

        //Use hashmap to store user credentials
        HashMap<String, String> user = new HashMap<String, String>();

        // user name
        user.put(KEY_PF, pref.getString(KEY_PF, null));

        // user email id
        user.put(KEY_EMAIL, pref.getString(KEY_EMAIL, null));
        user.put(KEY_LEVEL, pref.getString(KEY_LEVEL, null));

        // return user
        return user;
    }

    public HashMap<String, String> getNewMODetails(){

        //Use hashmap to store user credentials
        HashMap<String, String> MO = new HashMap<String, String>();


        MO.put(KEY_MO, pref.getString(KEY_MO, null));
        MO.put(KEY_Machine, pref.getString(KEY_Machine, null));
        MO.put(KEY_MATERIAL, pref.getString(KEY_MATERIAL, null));
        MO.put(KEY_PFOPT, pref.getString(KEY_PFOPT, null));
        MO.put(KEY_Task, pref.getString(KEY_Task, null));
        // return user
        return MO;
    }
    /**
     * Clear session details
     * */
    public void logoutUser(){

        // Clearing all user data from Shared Preferences
        editor.clear();
        editor.commit();

        // After logout redirect user to Login Activity
        Intent i = new Intent(_context, MainActivity.class);

        // Closing all the Activities
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        // Add new Flag to start new Activity
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // Staring Login Activity
        _context.startActivity(i);
    }

    public void ResetData(){

        // Clearing all user data from Shared Preferences
        editor.clear();
        editor.commit();

        // After logout redirect user to Login Activity
        Intent i = new Intent(_context, Operation.class);

        // Closing all the Activities
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        // Add new Flag to start new Activity
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // Staring Login Activity
        _context.startActivity(i);
    }

    // Check for login
    public boolean isUserLoggedIn(){
        return pref.getBoolean(IS_USER_LOGIN, false);
    }
}

пожалуйста, помогите мне, поскольку я не знал, как его изменить

...