how to fix java.lang.IllegalStateException:

332
02 июля 2018, 19:30
E/AndroidRuntime: FATAL EXCEPTION: main
              Process: tj.ttu.ttu, PID: 15033
              java.lang.IllegalArgumentException: Expected receiver of type tj.ttu.ttu.login, but got android.view.ContextThemeWrapper
                  at java.lang.reflect.Method.invoke(Native Method)
                  at android.view.View$DeclaredOnClickListener.onClick(View.java:4735)
                  at android.view.View.performClick(View.java:5697)
                  at android.widget.TextView.performClick(TextView.java:10826)
                  at android.view.View$PerformClick.run(View.java:22526)
                  at android.os.Handler.handleCallback(Handler.java:739)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:158)
                  at android.app.ActivityThread.main(ActivityThread.java:7224)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

java code

public class login extends AppCompatActivity {
    EditText pwd, lgn;
    AlertDialog alertDialogw;
    String FileName = "lgn_pwd";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        pwd = (EditText) findViewById(R.id.pwd);
        lgn = (EditText) findViewById(R.id.lgn);
    }
    class background_worker extends AsyncTask<String, Void, String> {
        Context context;
        AlertDialog alertDialog;
        background_worker(Context ctx) {
            context = ctx;
        }
        @Override
        public String doInBackground(String... params) {
            String type = params[0];
            String login_url = "http://77.95.1.234/api/v1/index.php";
            if (type.equals("login")) {
                try {
                    String username = params[1];
                    String password = params[2];
                    URL url = new URL(login_url);
                    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                    httpURLConnection.setRequestMethod("POST");
                    httpURLConnection.setDoOutput(true);
                    httpURLConnection.setDoInput(true);
                    OutputStream outputStream = httpURLConnection.getOutputStream();
                    BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
                    String post_data = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(username, "UTF-8") + "&"
                            + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8")+"&"
                            + URLEncoder.encode("route", "UTF-8") + "=" + URLEncoder.encode("auth", "UTF-8")+"&"
                            + URLEncoder.encode("operation", "UTF-8") + "=" + URLEncoder.encode("login", "UTF-8");
                    bufferedWriter.write(post_data);
                    bufferedWriter.flush();
                    bufferedWriter.close();
                    outputStream.close();
                    InputStream inputStream = httpURLConnection.getInputStream();
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
                    String result = "";
                    String line = "";
                    while ((line = bufferedReader.readLine()) != null) {
                        result += line;
                    }
                    bufferedReader.close();
                    inputStream.close();
                    httpURLConnection.disconnect();
                    return result;
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }
        @Override
        protected void onPreExecute() {
            alertDialog = new AlertDialog.Builder(context).create();
            alertDialog.setTitle("Статус входа");
        }
        @Override
        public void onPostExecute(String result) {
            JSONObject dataJsonObj = null;
    String replace="";
    String token="", error ="",message="";
            try {
                dataJsonObj = new JSONObject(result);
              //  JSONArray data = dataJsonObj.getJSONArray("data");
                error = dataJsonObj.getString("error");
                if (error == "true"){
                    message = dataJsonObj.getString("message");
                    alertDialog.setMessage(message);
                    alertDialog.show();
                }else{
                    JSONObject secondFriend = dataJsonObj.getJSONObject("data");
                    token = secondFriend.getString("token");
                    saveFile();
                    Intent i = new Intent(login.this, home.class);
                    i.putExtra("token", token);
                    startActivity(i);
                //alertDialog.setMessage(token);
                }
            } catch (JSONException e) {
                e.printStackTrace();
                Toast.makeText(login.this, "Ошибка"+e, Toast.LENGTH_SHORT).show();
                alertDialog.setMessage("оШИБКА: "+e);
            }
        }
        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }
    }
    public void signin (View v){
        String loginn = lgn.getText().toString();
        String passwords = pwd.getText().toString();
        alertDialogw = new AlertDialog.Builder(this).create();
        alertDialogw.setTitle("Оповещение");
        String type = "login";
        if (loginn.matches("") | passwords.matches("")) {
            Toast.makeText(login.this, "Поле логин или пароль пусто!", Toast.LENGTH_SHORT).show();
        }else if(loginn.matches("07-5963/15" )){
            Toast.makeText(login.this, "Пользователь "+loginn+" заблокирован!", Toast.LENGTH_SHORT).show();
        }else if (loginn.matches("07-5952/15")) {
            Toast.makeText(login.this, "Пользователь "+loginn+" заблокирован!", Toast.LENGTH_SHORT).show();
        }else{
            if (!isOnline()) {
                runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(login.this, "Нет соединения с интернетом!", Toast.LENGTH_LONG).show();
                    }
                });
            } else {
                background_worker backgroundWorker = new background_worker(this);
                backgroundWorker.execute(type, loginn, passwords);
            }
        }
    }
    protected boolean isOnline() {
        String cs = Context.CONNECTIVITY_SERVICE;
        ConnectivityManager cm = (ConnectivityManager)
                getSystemService(cs);
        if (cm.getActiveNetworkInfo() == null) {
            return false;
        } else { return true; }
    }
    private void saveFile(){
        String strLogin = lgn.getText().toString();
        String strPassword = pwd.getText().toString();
        SharedPreferences sharedPreferences = getSharedPreferences(FileName,Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("login", strLogin);
        editor.putString("password", strPassword);
        editor.commit();
    }
}

Код xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true"
tools:context="tj.ttu.ttu.login">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:orientation="vertical"
    android:paddingLeft="24dp"
    android:paddingRight="24dp">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="120dp"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/logo_white" />
    <!-- Email Label -->
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:hintTextAppearance="@style/MyHintText"
        app:errorEnabled="true"
        android:textColorHint="@android:color/background_light">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/lgn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="#ffffff"
            android:hint="@string/lgn_edt"
            android:theme="@style/MyEditText"
            android:inputType="textEmailAddress"
            android:textColor="@android:color/background_light"
            android:textColorHint="@android:color/background_light"
            android:textColorLink="@android:color/background_light" />
    </android.support.design.widget.TextInputLayout>
    <!-- Password Label -->
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:errorEnabled="true"
        app:passwordToggleContentDescription="description"
        app:passwordToggleEnabled="true"
        app:passwordToggleTint="#fff"
        android:textColorHint="@android:color/background_light"
        app:hintTextAppearance="@style/MyHintText"
        >
        <android.support.design.widget.TextInputEditText
            android:id="@+id/pwd"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@android:color/background_light"
            android:hint="@string/pwd_edt"
            android:inputType="textPassword"
            android:theme="@style/MyEditText"
            android:textColor="@android:color/background_light"
            android:textColorHint="@android:color/background_light"
            android:textColorLink="@android:color/background_light" />
    </android.support.design.widget.TextInputLayout>
    <android.support.v7.widget.AppCompatButton
        android:id="@+id/btnlogin"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="24dp"
        android:layout_marginTop="24dp"
        android:padding="12dp"
        android:text="@string/login"
        android:textColor="@android:color/background_light"
        android:onClick="signin"
        android:theme="@style/Theme.MaterialButton" />
</LinearLayout>

READ ALSO
Сохранение поведения во вложенных Map

Сохранение поведения во вложенных Map

Делаю игру для учебного проектаНа этапе инициализации у меня будет несколько вариантов выбора: первый boolean мод разработчика, вторым будет...

192
Digital Asset Links file not found

Digital Asset Links file not found

Я хочу сделать имплементацию диплинк

175
Неправильное поведение программы (Java)

Неправильное поведение программы (Java)

Описание проблемы скорее будет понятнее представленным кодом:

173
Как получить создателя файла в git

Как получить создателя файла в git

Всем привет! Как можно получить автора какого-либо файла, сохраненного в git репозитории, с помощью Java (использую класс JGit для подключения к git) ? И вообще...

177