gpt4 book ai didi

android - 在 onClick 处理程序的 Activity 类 android.view.ContextThemeWrapper 中找不到方法 onClick(View)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:01 28 4
gpt4 key购买 nike

我不知道我的应用程序现在发生了什么。
我收到这条消息 Could not find a method onClick(View) in the activity class android.view.ContextThemeWrapper for onClick handler
一切都很好,我想...
这是我的 Activity xml 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#9EC5E2"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/Theme.AppCompat.Light"
tools:context="com.tumta.henrique.teste.view.LoginActivity">

<LinearLayout
android:id="@+id/layout_campos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="@string/text_usuario"
android:textSize="35sp" />

<EditText
android:id="@+id/edit_usuario"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="@string/text_senha"
android:textSize="35sp" />

<EditText
android:id="@+id/edit_senha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:password="true" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/layout_campos"
android:layout_marginTop="50dp"
android:orientation="horizontal">

<Button
android:id="@+id/button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:onClick="onClick"/>

<Button
android:id="@+id/button_cancelar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:onClick="onClick"
android:text="Cancelar" />

</LinearLayout>


</RelativeLayout>

这是我的 Activity :

package com.tumta.henrique.teste.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.tumta.henrique.teste.R;
import com.tumta.henrique.teste.model.ConsultaLogin;

public class LoginActivity extends ActionBarActivity implements ConsultaLogin.ConsultaConcluidaLoginListener {


EditText txtUsuario, txtSenha;
ActionBar actionbar;
Button btnOk, btnCancelar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new ConsultaLogin(this).execute();
setContentView(R.layout.activity_login);
txtUsuario = (EditText) findViewById(R.id.edit_usuario);
txtSenha = (EditText) findViewById(R.id.edit_senha);
actionbar = getSupportActionBar();
actionbar.hide();
btnOk = (Button) findViewById(R.id.button_ok);
btnCancelar = (Button) findViewById(R.id.button_cancelar);
}

public void onClick(View view) {
Toast.makeText(this, "test", Toast.LENGTH_SHORT);
//ConsultaLogin.login = txtUsuario.getText().toString();
//ConsultaLogin.senha = txtSenha.getText().toString();
//new ConsultaLogin(this).execute();
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_login, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@Override
public void onConsultaConcluida(String result) {
if (result == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Erro");
builder.setMessage("Usuario ou Senha Incorreto!");
builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
txtUsuario.getText().clear();
txtSenha.getText().clear();
txtUsuario.requestFocus();
}
});
} else {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
}

我不知道这里出了什么问题。有人能帮我吗?


编辑
我的完整错误堆栈跟踪:

06-18 08:40:40.027  27976-27976/com.tumta.henrique.teste E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.tumta.henrique.teste, PID: 27976
java.lang.IllegalStateException: Could not find a method onClickOk(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'button_ok'
at android.view.View$1.onClick(View.java:4007)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NoSuchMethodException: onClickOk [class android.view.View]
at java.lang.Class.getMethod(Class.java:664)
at java.lang.Class.getMethod(Class.java:643)
at android.view.View$1.onClick(View.java:4000)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

最佳答案

找到了解决方案..我不知道为什么,但在做了一些搜索后我看到一些帖子说这是 Android 5.0 或更高版本上的问题..
解决方案是删除主题 标签来 self 的 layout.xml 文件。

关于android - 在 onClick 处理程序的 Activity 类 android.view.ContextThemeWrapper 中找不到方法 onClick(View),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30901906/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com