在没有达到点击事件的情况下按下按钮时应用程序崩溃

问题描述 投票:0回答:1

在我的Android Studio应用程序中,我设计了一个屏幕(不是使用XML,而是使用设计模式)。我已经将我的一个按钮的属性设置为类中的public method

这是我的按钮

设置onClick属性

enter image description here

表单的类代码

package com.example.my_test_app;

import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ftpDetails extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_ftp_details);
    setTitle(R.string.ftpTitle);
}

public void saveFTPSettings(View v) {

    // Set controls
    Button btn = (Button) v;
    TextView txtServer = (TextView) findViewById(R.id.txtServer);
    TextView txtFolder = (TextView) findViewById(R.id.txtFolder);
    TextView txtUsername = (TextView) findViewById(R.id.txtUsername);
    TextView txtPassword = (TextView) findViewById(R.id.txtPassword);

    // Check that all text boxes have a value in them
    if (txtServer.getText().length() == 0)
    {
        // MESSAGE BOX
        AlertDialog.Builder msg = new AlertDialog.Builder(this);
        msg.setTitle("Enter Server");
        msg.setMessage("Please enter a server address.");
        msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Leave this blank, this will mean nothing happens, the msg just disappears
            }
        });
    }

    if (txtFolder.getText().length() == 0)
    {
        // MESSAGE BOX
        AlertDialog.Builder msg = new AlertDialog.Builder(this);
        msg.setTitle("Enter Folder");
        msg.setMessage("Please enter a folder to use.");
        msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Leave this blank, this will mean nothing happens, the msg just disappears
            }
        });
    }

    if (txtUsername.getText().length() == 0)
    {
        // MESSAGE BOX
        AlertDialog.Builder msg = new AlertDialog.Builder(this);
        msg.setTitle("Enter Username");
        msg.setMessage("Please enter your username.");
        msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Leave this blank, this will mean nothing happens, the msg just disappears
            }
        });
    }

    if (txtPassword.getText().length() == 0)
    {
        // MESSAGE BOX
        AlertDialog.Builder msg = new AlertDialog.Builder(this);
        msg.setTitle("Enter Server");
        msg.setMessage("Please enter a your password.");
        msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Leave this blank, this will mean nothing happens, the msg just disappears
            }
        });
    }



    //MyDBHandler dbHandler = new MyDBHandler();
    //String _filePath = this.getFilesDir().toString() + "/";

    //SQLiteDatabase _db = SQLiteDatabase.openDatabase(_filePath + dbHandler.DATABASE_NAME, null, 0);

    //ContentValues initialValues = new ContentValues(4);
    //initialValues.put(dbHandler.COLUMN_FTP_SERVER, txtServer.getText().toString());
    //initialValues.put(dbHandler.COLUMN_FTP_FOLDER, txtFolder.getText().toString());
    //initialValues.put(dbHandler.COLUMN_FTP_USERNAME, txtUsername.getText().toString());
    //initialValues.put(dbHandler.COLUMN_FTP_PASSWORD, txtPassword.getText().toString());

    //_db.insert(dbHandler.TABLE_FTP, null, initialValues);

}

}

我在Button btn = (Button) v上放了一个断点。但是,当我按下按钮时,断点不会被击中,应用程序就会关闭。

这是我在Android Studio的调试窗口中获得的

E / libc:访问被拒绝查找属性“vendor.debug.egl.swapinterval”W / RenderThread:type = 1400 audit(0.0:1269):avc:denied {read} for name =“u:object_r:vendor_default_prop:s0”dev =“tmpfs”ino = 22761 scontext = u:r:untrusted_app:s0:c129,c256,c512,c768 tcontext = u:object_r:vendor_default_prop:s0 tclass = file permissive = 0 D / AndroidRuntime:关闭VM W / RenderThread: type = 1400 audit(0.0:1270):avc:denied {read} for name =“u:object_r:vendor_default_prop:s0”dev =“tmpfs”ino = 22761 scontext = u:r:untrusted_app:s0:c129,c256, c512,c768 tcontext = u:object_r:vendor_default_prop:s0 tclass = file permissive = 0 E / libc:访问被拒绝查找属性“vendor.debug.egl.swapinterval”W / RenderThread:type = 1400 audit(0.0:1271):avc :拒绝{read} for name =“u:object_r:vendor_default_prop:s0”dev =“tmpfs”ino = 22761 scontext = u:r:untrusted_app:s0:c129,c256,c512,c768 tcontext = u:object_r:vendor_default_prop: s0 tclass = file permissive = 0 E / libc:访问被拒绝查找属性“vendor.debug.egl.swapinterval”W / Ren derThread:type = 1400 audit(0.0:1272):avc:denied {read} for name =“u:object_r:vendor_default_prop:s0”dev =“tmpfs”ino = 22761 scontext = u:r:untrusted_app:s0:c129, c256,c512,c768 tcontext = u:object_r:vendor_default_prop:s0 tclass = file permissive = 0 E / libc:拒绝查找属性“vendor.debug.egl.swapinterval”E / AndroidRuntime:FATAL EXCEPTION:main进程:com.example .my_test_app,PID:8293 java.lang.IllegalStateException:无法在父或祖先中找到方法saveFTPSettings(View)用于android的onClick属性:在视图类android.support.v7.widget.AppCompatButton上定义的id为'btnSave'at android.support.View.performClick(android.sview.View.perform Click) View.java:6669)在Android.view.View.access $ 3100(View.java)的android.view.View.performClickInternal(View.java:6638) :789)在Android.os.Handler.dispatchMessage(Handler.java:99)的android.view.View $ PerformClick.run(View.java:26145)android.os.Handler.handleCallback(Handler.java:873)在android.os.Looper.loop(Looper.java:193)的android.app.ActivityThread.main(ActivityThread.java:6863),位于com.android.internal的java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.ZygoteInit.main中的.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:537)W / RenderThread:type = 1400 audit(0.0:1273):avc:拒绝{read} for name =“u:object_r:vendor_default_prop:s0”dev =“tmpfs”ino = 22761 scontext = u:r:untrusted_app:s0:c129,c256,c512,c768 tcontext = u:object_r:vendor_default_prop:s0 tclass = file permissive = 0 E / libc:拒绝查找属性“vendor.debug.egl.swapinterval”I / chatty:uid = 10129(com.example.my_test_app)RenderThread相同的1行E / libc:访问被拒绝查找属性“ vendor.debug.egl.swapinterval“W / OPDiagnose:getService:OPDiagnoseService NULL E / libc:Acce ss拒绝查找属性“vendor.debug.egl.swapinterval”I / chatty:uid = 10129(com.example.my_test_app)RenderThread相同的3行E / libc:访问被拒绝查找属性“vendor.debug.egl.swapinterval”D / OSTracker:OS事件:崩溃I /处理:发送信号。 PID:8293 SIG:9与目标VM断开连接,地址:'localhost:8600',transport:'socket'

当我按下按钮时,为什么我的应用程序关闭?我可以很好地输入文本框,它只是按下按钮似乎关闭它。

java android debugging
1个回答
0
投票

我有同样的问题,在我的情况下,我将XML中的Button更改为android.support.v7.widget.AppCompatButton并且它有效。

更改

<Button
        .... />

<android.support.v7.widget.AppCompatButton
        .... />
© www.soinside.com 2019 - 2024. All rights reserved.