0

これはここへの私の最初の投稿なので、さらに詳細が必要な場合はお知らせください。

SQLite データベースを検索してデータを画面にロードしようとしていますが、logCat から次のエラーが発生し続けます。

06-10 20:44:22.838: E/Trace(875): error opening trace file: No such file or directory (2)
06-10 20:44:24.627: I/Choreographer(875): Skipped 30 frames!  The application may be doing too much work on its main thread.
06-10 20:44:24.727: D/gralloc_goldfish(875): Emulator without GPU emulation detected.
06-10 20:44:26.956: D/AndroidRuntime(875): Shutting down VM
06-10 20:44:26.956: W/dalvikvm(875): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-10 20:44:27.006: E/AndroidRuntime(875): FATAL EXCEPTION: main
06-10 20:44:27.006: E/AndroidRuntime(875): java.lang.NullPointerException
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
06-10 20:44:27.006: E/AndroidRuntime(875):  at com.Jamie.dosanddonts.DosAndDontsDbAdapter.findCountry(DosAndDontsDbAdapter.java:331)
06-10 20:44:27.006: E/AndroidRuntime(875):  at com.Jamie.dosanddonts.Core.searchDatabase(Core.java:64)
06-10 20:44:27.006: E/AndroidRuntime(875):  at com.Jamie.dosanddonts.HomeScreen$1.onClick(HomeScreen.java:39)
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.view.View.performClick(View.java:4204)
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.view.View$PerformClick.run(View.java:17355)
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.os.Handler.handleCallback(Handler.java:725)
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.os.Looper.loop(Looper.java:137)
06-10 20:44:27.006: E/AndroidRuntime(875):  at android.app.ActivityThread.main(ActivityThread.java:5041)
06-10 20:44:27.006: E/AndroidRuntime(875):  at java.lang.reflect.Method.invokeNative(Native Method)
06-10 20:44:27.006: E/AndroidRuntime(875):  at java.lang.reflect.Method.invoke(Method.java:511)
06-10 20:44:27.006: E/AndroidRuntime(875):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-10 20:44:27.006: E/AndroidRuntime(875):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-10 20:44:27.006: E/AndroidRuntime(875):  at dalvik.system.NativeStart.main(Native Method)
06-10 20:44:32.236: I/Process(875): Sending signal. PID: 875 SIG: 9
06-10 20:44:34.827: D/gralloc_goldfish(892): Emulator without GPU emulation detected.

次の 4 つのメイン クラスがあります。

package com.Jamie.dosanddonts;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class HomeScreen extends Activity {

    Core myCore;
    DosAndDontsDbAdapter myDb;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.myDb = new DosAndDontsDbAdapter(this);
        this.myCore = new Core(myDb);
        setContentView(R.layout.activity_home_screen);
        Button france = null,germany = null,italy = null,spain = null,unitedKingdom = null;

        final Button buttons[] = {france, germany, italy, spain, unitedKingdom};
        int ids[] = {R.id.France,R.id.Germany,R.id.Italy,R.id.Spain,R.id.United_Kingdom};

        for(int i=0;i<buttons.length;i++)
        {
            buttons[i]=(Button) findViewById(ids[i]);
            buttons[i].setOnClickListener(new View.OnClickListener()        

        {           
            @Override
            public void onClick(View v) 
            {

                Intent nextScreen = new Intent(getApplicationContext(), DataScreen.class);
                startActivity(nextScreen);
                //int temp = v.getId();
                myCore.searchDatabase("Germany");           

            }
        }); 

    }}

}

データスクリーン:

package com.Jamie.dosanddonts;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;

public class DataScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_data_screen);
        // Show the Up button in the action bar.
        setupActionBar();
        Button homeButton = (Button) this.findViewById(R.id.homeButton);
        TextView textView = (TextView) this.findViewById(R.id.Country_name);
        textView.setText("help");
        homeButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) 
            {
                Intent nextScreen = new Intent(getApplicationContext(), HomeScreen.class);
                startActivity(nextScreen);

            }
        });
    }

    /**
     * Set up the {@link android.app.ActionBar}, if the API is available.
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setupActionBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-vs-back
            //
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

DosAndDontsDbAdapter:

package com.Jamie.dosanddonts;

import java.util.ArrayList;
import java.util.List;

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

public class DosAndDontsDbAdapter extends SQLiteOpenHelper {



    private static final String DATABASE_TABLE = "dosAndDonts";

    private static final String COUNTRY = "Country name";
    private static final String INDICATOR = "Indicator";
    private static final String DESCRIPTION = "Description";

    public DosAndDontsDbAdapter(Context context) {
        super(null, DATABASE_TABLE, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("Create table " + DATABASE_TABLE + " (" + COUNTRY
                + " TEXT, " + INDICATOR + " TEXT, " + DESCRIPTION
                + " TEXT);");

        db = this.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Shake hands when you greet someone.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Do say 'bonjour' or 'bonsoir'.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Flowers should be given in odd numbers but not 13.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always smile");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always arrive on time for dinner.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "When eating Do not rest your elbows on the table.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Don't refer to someone by their first name unless you are a close friend.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never offer cheap wine.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not begin eating until the hostess says 'bon appetit' ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not cut salad with a knife and fork. Fold the lettuce on to your fork. ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();


        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Shake hands when greeting and leaving someone.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When you have finished eating lay your knide and fork parallel across your plate.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When in a pub pay for a round of drinks for everyone in your group.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When eating The fork is held tines down so food is scooped on to the back of the fork.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When eating, Table manners are Continental.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never get in their personal space.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "It's inapropriate to ask personal questions.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "They'll become unconfortalbe if engage in prolonged eye contact.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "When eating don't rest your elbows on the table.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "DON'T make the V for victory sign with your palm facing yourself.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();


        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When greeting The usual handshake with direct eye contact.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Have calling card made.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you bring wine, make sure it is a good vintage.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you are invited to a meal, bring gift-wrapped such as wine or chocolates. ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Table manners are Continental.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never give your business card in lieu of a calling card in a social situation.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give chrysanthemums as they are used at funerals.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not keep your hands in your lap during the meal.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give red flowers as they indicate secrecy. ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give yellow flowers as they indicate jealousy.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();

        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "A quick, firm handshake is the traditional greeting.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Titles are very important and denote respect.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When entering a room, shake hands with everyone individually.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Yellow roses or tea roses are always well received. ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you bring wine, it should be imported.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give lilies or chrysanthemums as they are used at funerals. ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never arrive early, aslways on time.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not begin eating until the hostess starts.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not rest your elbows on the table.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not cut lettuce in a salad. Fold it using your knife and fork.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();


        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Many men use a two-handed shake.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always bring a gift to someones house.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always keep your hands visible when eating.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Use utensils to eat most food.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you have not finished eating, cross your knife and fork on your plate.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not begin eating until the hostess starts.  ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not get up until the guest of honour does. ");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never toast first always allow the host to.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "When at dinner don't sit unless invited to do so.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Don't go bare cheasted anywhere other than the beach or poolside.");
        db.insert(DATABASE_TABLE, COUNTRY, cv);
        cv.clear();
        db.close();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }

     Country findCountry(String country)
       {
        int index = 0;
        SQLiteDatabase db=this.getReadableDatabase();
        List <DosAndDonts> dosNDonts = new ArrayList <DosAndDonts>();

        Cursor cursor = db.query(DATABASE_TABLE, new String[] { COUNTRY,
                INDICATOR, DESCRIPTION }, COUNTRY + "=?",
                new String[] { String.valueOf(country) }, null, null, null, null);

        Country returnedCountry = new Country();
        returnedCountry.setName(cursor.getString(0));
        do
        {

            dosNDonts.add(new DosAndDonts(cursor.getString(index + 1),
                        cursor.getString(index + 2)));


            index = index + 3;
            //returnedCountry.setCountryDosAndDonts(countryDosAndDonts)

        }while(cursor.moveToNext());

        returnedCountry.setCountryDosAndDonts(dosNDonts);


       //Cursor cur = db.rawQuery("FIND "+country+" as _id from "+DATABASE_TABLE,new String [] {});

        return returnedCountry;
       }


}

芯:

package com.Jamie.dosanddonts;

import java.util.List;

import android.widget.TextView;

public class Core {

    private DosAndDontsDbAdapter myDosAndDontsDbAdapter;
    private TextView temp;
    private Country currentCountry;

    public Core(DosAndDontsDbAdapter myDb) {

        myDosAndDontsDbAdapter = myDb;

    }

    public Core() {
        // TODO Auto-generated constructor stub
    }

    public void displayResult() 
    {
        TextView country = (TextView) temp.findViewById(R.id.Country_name);
        TextView do1 = (TextView) temp.findViewById(R.id.Do1);
        TextView do2 = (TextView) temp.findViewById(R.id.Do2);
        TextView do3 = (TextView) temp.findViewById(R.id.Do3);
        TextView do4 = (TextView) temp.findViewById(R.id.Do4);
        TextView do5 = (TextView) temp.findViewById(R.id.Do5);
        TextView dont1 = (TextView) temp.findViewById(R.id.Dont1);
        TextView dont2 = (TextView) temp.findViewById(R.id.Dont2);
        TextView dont3 = (TextView) temp.findViewById(R.id.Dont3);
        TextView dont4 = (TextView) temp.findViewById(R.id.Dont4);
        TextView dont5 = (TextView) temp.findViewById(R.id.Dont5);

        TextView dos[] = { do1, do2, do3, do4, do5 };
        TextView donts[] = { dont1, dont2, dont3, dont4, dont5 };

        int doCounter = 0;
        int dontCounter = 0;
        int index = 0;
        List <DosAndDonts> dosNDonts = currentCountry.getCountryDosAndDonts(); 

        country.setText(currentCountry.getName());

        while (index < dosNDonts.size())
        {
            if (dosNDonts.get(index).getIndicator().equals("Do"))
            {
                dos[doCounter].setText(dosNDonts.get(index).getDescription());
                doCounter++;
            } 
            else 
            {
                donts[dontCounter].setText(dosNDonts.`enter code here`get(index).getDescription());
                dontCounter++;
            }
            index++;
        }
    }

    public void searchDatabase(String searchedCountry) {
        currentCountry = myDosAndDontsDbAdapter.findCountry(searchedCountry);
        //TextView country = (TextView) temp.findViewById(R.id.Country_name);
        //country.setText(searchedCountry);
        this.displayResult();
    }

}

enter code here

エラーをさらに見つけようとする引数「Germany」を渡しましたが、うまくいきませんでした。したがって、ユーザーはhomeScreenで国を選択し、コアクラスがその国の情報をデータベースで検索してdataScreenにロードするように呼び出します。検索データベースコードを削除すると、アプリは画面間を正常に移動しますが、検索データベースコードを使用しますアプリはホーム画面をロードしますが、国をクリックするとすぐに logCat エラーが表示されます。

こんにちは、みんな

ご回答いただきありがとうございます。アダプター クラスで引数を null として渡さないようにし、do while を a while に変更するという変更を行いましたが、logCat で次のエラーが発生しています。

06-11 20:23:06.520: D/gralloc_goldfish(1268): GPU エミュレーションなしのエミュレーターが検出されました。06-11 20:23:10.620: 私/Choreographer(1268): 50 フレームスキップしました! アプリケーションがメイン スレッドで処理しすぎている可能性があります。06-11 20:23:15.629: D/AndroidRuntime(1268): VM をシャットダウンしています 06-11 20:23:15.629: W/dalvikvm(1268): threadid=1: キャッチされない例外で終了するスレッド (group=0x40a71930) 06 -11 20:23:15.699: E/AndroidRuntime(1268): 致命的な例外: メイン 06-11 20:23:15.699: E/AndroidRuntime(1268): java.lang.IllegalStateException: getDatabase が再帰的に呼び出された 06-11 20:23 :15.699: E/AndroidRuntime(1268): android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:204) 06-11 20:23:15.699: E/AndroidRuntime(1268): android.database.sqlite で。 SQLiteOpenHelper.getWritableDatabase (SQLiteOpenHelper.java:164) 06-11 20:23:15.699:

forループを使用してボタンの割り当てを削除し、単一のボタンGermanyに置き換えて試してみましたが、logCatで同じエラーが発生します。

よろしくチャピンチ

4

3 に答える 3

1

cursor.moveToFirst() を呼び出さないため、最初にカーソルを使用しようとすると、行 -1 にアクセスしようとします。1 つの代替手段は、do-while ループを while ループに変更することです。

while(cursor.moveToNext())
{

        dosNDonts.add(new DosAndDonts(cursor.getString(index + 1),
                    cursor.getString(index + 2)));


        index = index + 3;
        //returnedCountry.setCountryDosAndDonts(countryDosAndDonts)

}
于 2013-06-10T21:12:29.270 に答える
0

CommonsWare は正しいNullPointerExceptionです。これは、与えられたコンテキストを通過する代わりに super(null ... ) を呼び出した結果です。

これが理由です:

// mContext is null
224 db = mContext.openOrCreateDatabase(mName, mEnableWriteAheadLogging ?
225 Context.MODE_ENABLE_WRITE_AHEAD_LOGGING : 0,
226 mFactory, mErrorHandler);
于 2013-06-10T22:18:34.600 に答える