Android onClick事件中的ForceClose错误,无法将某些内容保存到数据库中

Android onClick事件中的ForceClose错误,无法将某些内容保存到数据库中,android,Android,在布局中定义onClick事件时出错。 在我的代码中,我希望在单击时,它会将我的内容保存在我自己的数据库中,但我总是会遇到“强制关闭错误”,我不知道为什么 我试图找出问题所在,如果我忽略了数据库,那么它就会工作并转到另一个站点 以下是我的活动代码: package de.retowaelchli.filterit; import android.app.Activity; import android.content.Intent; import android.os.Bundle; impo

在布局中定义
onClick
事件时出错。
在我的代码中,我希望在单击时,它会将我的内容保存在我自己的数据库中,但我总是会遇到“强制关闭错误”,我不知道为什么

我试图找出问题所在,如果我忽略了数据库,那么它就会工作并转到另一个站点

以下是我的活动代码:

package de.retowaelchli.filterit;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioGroup;

import de.retowaelchli.filterit.database.ADFilterDBAdapter;


public class ADFilterConfigActivity extends Activity {

    //Variablen deklaration
    private ADFilterDBAdapter mDbHelper;
    private String name;
    private String keyword;
    private String cache;
    private String save = "";


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.autodelete_config);
        radiobuttoncheck();

        //Hier wir die Datenbank aufgerufen
        mDbHelper = new ADFilterDBAdapter(this);
        mDbHelper.open();


        //Hier werden die EditTextfelder gesucht
        EditText edtTextName=(EditText )findViewById(R.id.ADConfigName);
        EditText edtTextKeyword=(EditText )findViewById(R.id.ADConfigKeyword);

        //Hier wird der Inhalt der EditText boxen in einen String gespeichert
        name = edtTextName.getText().toString();
        keyword = edtTextKeyword.getText().toString();
        }

        private void radiobuttoncheck() {

        //Hier wird ausgewertet welcher Button geklickt wurde
        RadioGroup rg = (RadioGroup) findViewById(R.id.adcachegroup);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, final int checkedId) {
                switch (checkedId) {
                case R.id.adcache_true:
                    save = new StringBuilder(save).append("true").toString();
                    cache = save.toString();

                    break;
                case R.id.adcache_false:
                    save = new StringBuilder(save).append("false").toString();
                    cache = save.toString();

                    break;
                        }
                }
            });
        }
        //Hier werden die Daten in die Datenbank geschreiben und es wird aufs alte register verwiesen
        public void onClickADConfigSave(){

            mDbHelper.createADFilter(name, keyword, cache);

            final Intent i = new Intent(this, ADeleteActivity.class);
            startActivity(i);

        }
 }
下面是我的数据库适配器的代码:

package de.retowaelchli.filterit.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ADFilterDBAdapter {

        public static final String ROW_ID = "_id";
        public static final String NAME = "name";
        public static final String KEYWORD = "keyword";
        public static final String CACHE = "cache";

        private static final String DATABASE_TABLE = "adfilter";

        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDb;

        private final Context mCtx;

        private static class DatabaseHelper extends SQLiteOpenHelper {

            DatabaseHelper(Context context) {
                super(context, DBAdapter.DATABASE_NAME, null, DBAdapter.DATABASE_VERSION);
            }

            @Override
            public void onCreate(SQLiteDatabase db) {
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            }
        }

        /**
         * Constructor - takes the context to allow the database to be
         * opened/created
         * 
         * @param ctx
         *            the Context within which to work
         */
        public ADFilterDBAdapter(Context ctx) {
            this.mCtx = ctx;
        }

        /**
         * Open the cars database. If it cannot be opened, try to create a new
         * instance of the database. If it cannot be created, throw an exception to
         * signal the failure
         * 
         * @return this (self reference, allowing this to be chained in an
         *         initialization call)
         * @throws SQLException
         *             if the database could be neither opened or created
         */
        public ADFilterDBAdapter open() throws SQLException {
            this.mDbHelper = new DatabaseHelper(this.mCtx);
            this.mDb = this.mDbHelper.getWritableDatabase();
            return this;
        }

        /**
         * close return type: void
         */
        public void close() {
            this.mDbHelper.close();
        }

        /**
         * Create a new car. If the car is successfully created return the new
         * rowId for that car, otherwise return a -1 to indicate failure.
         * 
         * @param name
         * @param model
         * @param year
         * @return rowId or -1 if failed
         */
        public long createADFilter(String name, String keyword, String cache){
            ContentValues initialValues = new ContentValues();
            initialValues.put(NAME, name);
            initialValues.put(KEYWORD, keyword);
            initialValues.put(CACHE, cache);
            return this.mDb.insert(DATABASE_TABLE, null, initialValues);
        }

        /**
         * Delete the car with the given rowId
         * 
         * @param rowId
         * @return true if deleted, false otherwise
         */
        public boolean deleteADFilter(long rowId) {

            return this.mDb.delete(DATABASE_TABLE, ROW_ID + "=" + rowId, null) > 0; //$NON-NLS-1$
        }

        /**
         * Return a Cursor over the list of all cars in the database
         * 
         * @return Cursor over all cars
         */
        public Cursor getAllADFilter() {

            return this.mDb.query(DATABASE_TABLE, new String[] { ROW_ID,
                    NAME, KEYWORD, CACHE }, null, null, null, null, null);
        }

        /**
         * Return a Cursor positioned at the car that matches the given rowId
         * @param rowId
         * @return Cursor positioned to matching car, if found
         * @throws SQLException if car could not be found/retrieved
         */
        public Cursor getADFilter(long rowId) throws SQLException {

            Cursor mCursor =

            this.mDb.query(true, DATABASE_TABLE, new String[] { ROW_ID, NAME,
                    KEYWORD, CACHE}, ROW_ID + "=" + rowId, null, null, null, null, null);
            if (mCursor != null) {
                mCursor.moveToFirst();
            }
            return mCursor;
        }

        /**
         * Update the car.
         * 
         * @param rowId
         * @param name
         * @param keyword
         * @param cache
         * @return true if the note was successfully updated, false otherwise
         */
        public boolean updateADFilter(long rowId, String name, String keyword,
                String cache){
            ContentValues args = new ContentValues();
            args.put(NAME, name);
            args.put(KEYWORD, keyword);
            args.put(CACHE, cache);

            return this.mDb.update(DATABASE_TABLE, args, ROW_ID + "=" + rowId, null) >0; 
        }

    }
这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:weightSum="1">

        <TextView 
        style="@style/NormalFont"
        android:text="@string/adconfig"     
        android:layout_weight="0.05" 
        android:clickable="false"
        />

        <TextView
            style="@style/SmallFont"
            android:text="@string/adname"
            android:layout_weight="0.03" />
        <EditText 
            android:layout_width="match_parent" 
            android:id="@+id/ADConfigName" 
            android:layout_weight="0.05" 
            android:layout_height="25dp"
            android:layout_marginBottom="20dp">
            <requestFocus></requestFocus>
        </EditText>

        <TextView
            style="@style/SmallFont"
            android:text="@string/adkeyword"
            android:layout_weight="0.03"
            />
        <EditText 
            android:layout_width="match_parent" 
            android:id="@+id/ADConfigKeyword" 
            android:layout_weight="0.05" 
            android:layout_height="25dp"
            android:layout_marginBottom="20dp">
            <requestFocus></requestFocus>
        </EditText>

            <TextView
            style="@style/SmallFont"
            android:text="@string/adcache"
            android:layout_weight="0.03"
             />
        <RadioGroup 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:orientation="horizontal"
            android:checkedButton="@+id/adcache" 
            android:id="@+id/adcachegroup"
            android:gravity="center" >

            <RadioButton 
                android:text="Yes" 
                android:id="@+id/adcache_true" 
                android:layout_width="80dip" 
                android:layout_height="wrap_content"
>
            </RadioButton>

            <RadioButton 
                android:text="No" 
                android:id="@+id/adcache_false" 
                android:layout_width="80dip" 
                android:layout_height="wrap_content">
            </RadioButton>
        </RadioGroup> 

        <TableLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ADConfigMainsite"
            android:layout_weight="0.76"
            android:gravity="bottom">   
                <TableRow 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"        
                    android:id="@+id/ADConfigMainsite"
                    android:onClick="onClickADConfigSave"
                    android:layout_weight="0.05"
                    android:gravity="bottom">
                        <TextView   
                            android:text="@string/adconfigsave" 
                            style="@style/NormalFont"   
                            android:gravity="bottom"/>
                 </TableRow>
    </TableLayout>


</LinearLayout>

这是LogCat日志:

08-31 13:56:42.183: WARN/dalvikvm(2345): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): FATAL EXCEPTION: main 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): java.lang.IllegalStateException: Could not find a method onClickADConfigSave(View) in the activity class de.retowaelchli.filterit.ADFilterConfigActivity for onClick handler on view class android.widget.TableRow with id 'ADConfigMainsite' 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.view.View$1.onClick(View.java:2178) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.view.View.performClick(View.java:2532) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.view.View$PerformClick.run(View.java:9277) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.os.Handler.handleCallback(Handler.java:587) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.os.Handler.dispatchMessage(Handler.java:92) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.os.Looper.loop(Looper.java:143) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.app.ActivityThread.main(ActivityThread.java:4196) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at java.lang.reflect.Method.invokeNative(Native Method) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at java.lang.reflect.Method.invoke(Method.java:507) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at dalvik.system.NativeStart.main(Native Method) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): Caused by: java.lang.NoSuchMethodException: onClickADConfigSave 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at java.lang.ClassCache.findMethodByName(ClassCache.java:247) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at java.lang.Class.getMethod(Class.java:962) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): at android.view.View$1.onClick(View.java:2171) 08-31 13:56:42.183: ERROR/AndroidRuntime(2345): ... 11 more 08-31 13:56:42.183: WARN/ActivityManager(1740): Force finishing activity de.retowaelchli.filterit/.ADFilterConfigActivity 08-31 13:56:42.693: WARN/ActivityManager(1740): Activity pause timeout for HistoryRecord{409895c0 de.retowaelchli.filterit/.ADFilterConfigActivity} 08-31 13:56:42.183:WARN/dalvikvm(2345):threadid=1:线程退出时出现未捕获异常(组=0x4001d5a0) 08-31 13:56:42.183:错误/AndroidRuntime(2345):致命异常:主 08-31 13:56:42.183:错误/AndroidRuntime(2345):java.lang.IllegalStateException:在id为“ADConfigMainsite”的视图类android.widget.TableRow上的onClick处理程序的活动类de.retowaelchli.filterit.ADFilterConfigActivity中找不到onClick配置保存(视图)方法 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):在android.view.view$1.onClick(view.java:2178) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):在android.view.view.performClick(view.java:2532) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):在android.view.view$PerformClick.run(view.java:9277) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于android.os.Handler.handleCallback(Handler.java:587) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于android.os.Handler.dispatchMessage(Handler.java:92) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于android.os.Looper.loop(Looper.java:143) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于android.app.ActivityThread.main(ActivityThread.java:4196) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于java.lang.reflect.Method.invokenactive(本机方法) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于java.lang.reflect.Method.invoke(Method.java:507) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-31 13:56:42.183:错误/AndroidRuntime(2345):在dalvik.system.NativeStart.main(本机方法) 08-31 13:56:42.183:错误/AndroidRuntime(2345):由以下原因引起:java.lang.NoSuchMethodException:onClickADConfigSave 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于java.lang.ClassCache.findMethodByName(ClassCache.java:247) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):位于java.lang.Class.getMethod(Class.java:962) 08-31 13:56:42.183:ERROR/AndroidRuntime(2345):在android.view.view$1.onClick(view.java:2171) 08-31 13:56:42.183:错误/AndroidRuntime(2345):。。。还有11个 2008-31 13:56:42.183:警告/活动管理器(1740):强制完成活动de.retowaelchli.filterit/.adfilterconfictivity 08-31 13:56:42.693:WARN/ActivityManager(1740):历史记录{409895c0 de.retowaelchli.filterit/.ADFilterConfigActivity}的活动暂停超时
提前感谢您的帮助。

找不到android:onClick=“onClickADConfigSave”分配的功能。这是因为
android:onClick
辅助的函数必须将
视图
作为参数(以识别单击了哪个
视图
,特别是当您将同一个onClick函数分配给多个函数时)

试着替换

public void onClickADConfigSave() { ...


未找到android:onClick=“onClickADConfigSave”分配的函数。这是因为
android:onClick
辅助的函数必须将
视图
作为参数(以识别单击了哪个
视图
,特别是当您将同一个onClick函数分配给多个函数时)

试着替换

public void onClickADConfigSave() { ...

您的方法“onClickADConfigSave”应定义为

public void onClickADConfigSave(View v)
您的方法“onClickADConfigSave”应定义为

public void onClickADConfigSave(View v)