E / cutils-trace(1221):打开跟踪文件时出错:没有这样的文件或目录(2)

时间:2014-01-17 12:17:16

标签: android sqlite android-layout android-sqlite android-spinner

当我点击“查找”按钮时,没有任何反应,LogCat会显示此错误消息 -

01-17 06:53:33.821: E/cutils-trace(1221): Error opening trace file: No such file or directory (2)
01-17 06:54:05.431: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:05.451: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:05.491: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:05.531: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:05.571: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:05.602: E/SoundPool(275): error loading /system/media/audio/ui/KeypressStandard.ogg
01-17 06:54:05.692: E/SoundPool(275): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-17 06:54:05.852: E/SoundPool(275): error loading /system/media/audio/ui/KeypressDelete.ogg
01-17 06:54:06.042: E/SoundPool(275): error loading /system/media/audio/ui/KeypressReturn.ogg
01-17 06:54:14.512: E/DictionaryBackupAgent(1148): Couldn't read from the cursor
01-17 06:54:22.752: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:22.762: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:22.782: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:22.812: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:22.842: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:54:22.852: E/SoundPool(275): error loading /system/media/audio/ui/KeypressStandard.ogg
01-17 06:54:22.872: E/SoundPool(275): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-17 06:54:22.892: E/SoundPool(275): error loading /system/media/audio/ui/KeypressDelete.ogg
01-17 06:54:22.935: E/SoundPool(275): error loading /system/media/audio/ui/KeypressReturn.ogg
01-17 06:55:13.171: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:55:13.191: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:55:13.211: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:55:13.231: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
01-17 06:55:13.261: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg

这是我的activity_main.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:orientation="horizontal"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="10dp"
        android:text="@string/heading"
        android:textSize="@dimen/heading"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Spinner
        android:id="@+id/spinner_dest"
        android:layout_width="200dp"
        android:layout_height="80dp"
        android:layout_alignLeft="@+id/spinner_src"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="15dp"
        android:paddingTop="30dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/spinner_dest"

        android:layout_marginLeft="5dp"
        android:layout_marginBottom="26dp"
        android:layout_marginTop="2dp"
        android:textSize="@dimen/text_spinner"
        android:text="@string/src" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/spinner_src"
        android:textSize="@dimen/text_spinner"
        android:layout_marginLeft="5dp"
        android:layout_marginBottom="29dp"
        android:text="@string/des" />

    <Spinner
        android:id="@+id/spinner_src"
        android:layout_width="200dp"
        android:layout_height="80dp"
        android:layout_below="@+id/spinner_dest"
        android:layout_toRightOf="@+id/textView3"
        android:paddingTop="30dp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/spinner_src"
        android:layout_marginTop="21dp"
        android:text="@string/button_find"
        android:onClick="onSearch" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button1"
        android:text="LASSDt"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>





This is my MainActivity.java

    package play.adi.adj;

    import java.io.IOException;



    import android.app.Activity;
    import android.app.Dialog;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.Spinner;
    import android.widget.TextView;
    import android.content.Intent;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteOpenHelper;





    public class MainActivity extends Activity implements OnItemClickListener, OnItemSelectedListener {

        public String spin_src,spin_des;
        private BusDb myDbHelper;
        String name,name2;
        byte[] no = new byte[10];
        Spinner spinner;
        Spinner spinner_des;
        String[] answer = new String[5];
        String[] lst = { 
                "AGARWAL FARM",
                "AJMERI GATE", 
                "BADI CHOPAR",
                "BHANKROTA",

                "CITY PLEX MALL-ASHRAM MARG",
                "CHANDPOLE",
                "CHOMU PULIA",
                "CHOTI CHOPAR",
                "COLLECTORATE",
                "DADI KA PHATAK",
                "DURGAPURA",
                "ESI",
                "GALTA GATE",
                "GANDHI NAGAR",
                "GOPAL PURA",
                "GPO",
                "HEERAPURA",
                "JAGATPURA",
                "KANOTA",
                "KHOL KE HANUMAN JI",
                "KHIRNI PHATAK",
                "KINGS ROAD",
                "KUNDA",
                "MAHARANI COLLEGE",

                "MALVIYA NAGAR",
                "NARAYAN SINGH CIRCLE",
                "NEW SANGANER ROAD",

                "PEETAL FACTORY",
                "PRATAP NAGAR",
                "PURANI CHUNGI",

                "RAMBAGH",
                "SANGANER",
                "SANGANER THANA",
                "SANGANERI GATE",
                "SINDHI CAMP",
                "SODALA",

                "SURYA NAGAR",


                "TONK PHATAK",
                "V.K.I ROAD NO.17"



    };


        Button sqlGetInfo;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            spinner = (Spinner) findViewById(R.id.spinner_src);
            spinner_des = (Spinner) findViewById(R.id.spinner_dest);

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, lst);
            spinner.setAdapter(adapter);
            spinner.setOnItemSelectedListener(this);


            //ArrayAdapter<String> adapter_des = new ArrayAdapter<String>(this,
                //  android.R.layout.simple_list_item_1, lst);
            spinner_des.setAdapter(adapter);
            spinner_des.setOnItemSelectedListener(this);

            //DataBaseHelper myDbHelper;



            boolean didItWork = true;
            try {

                 myDbHelper = new BusDb(this);

                    myDbHelper.open();

                for (byte i= 0; i<10;i++){
                    no[i] = 0;
                }
                name = "TODI";
                no[0] =1;
                myDbHelper.createEntry(name,no);

                for (byte i= 0; i<10;i++){
                    no[i] = 0;
                }
                name = "BADI CHOPAR";
                no[0] = 1; no[4] = 1;
                myDbHelper.createEntry(name,no);






                for (byte i= 0; i<10;i++){
                    no[i] = 0;
                }
                 name = "CITY PLEX MALL ASHRAM MARG";
                no[2] =1;no[7] =1; 
                myDbHelper.createEntry(name,no);

                for (byte i= 0; i<10;i++){
                    no[i] = 0;
                }
                 name = "GOPALPURA";
                no[2] = 1; no[6] = 1;no[8] = 1;
                myDbHelper.createEntry(name,no);
                myDbHelper.close();



            } catch (Exception e) {
                didItWork = false;
                String error = e.toString();
                Dialog d = new Dialog(this);
                d.setTitle("Database creation failed");
                TextView tv = new TextView(this);
                tv.setText(error);
                d.setContentView(tv);
                d.show();
            } finally {
                if (didItWork) {
                    Dialog d = new Dialog(this);
                    d.setTitle("Heck Yea!");
                    TextView tv = new TextView(this);
                    tv.setText("Success");
                    d.setContentView(tv);
                    d.show();
                }
            }









        }


        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            switch (arg0.getId()) {
            case R.id.button1:
                TextView tv_ans = (TextView) findViewById(R.id.textView4);
                //DataBaseHelper bus_db = new DataBaseHelper(this);
                //bus_db.openDataBase();
                myDbHelper.open();
                answer = myDbHelper.routeSearch(spin_src,spin_des);
                myDbHelper.close();
                tv_ans.setText(CharSequence(answer));
            //  Intent i = new Intent("play.adi.adj.ROUTEVIEW");
                //startActivity(i);


            }

        }


        private CharSequence CharSequence(String[] answer) {
            // TODO Auto-generated method stub
            CharSequence seq ="";
            for(int i =0;i<5;i++){
                if(answer[i] != null){
                    seq = seq + answer[i];
                }
            }
            return seq;
        }


        public void onSearch(View view){

        }


        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            switch(arg1.getId()){
            case R.id.spinner_dest:
                break;
            case R.id.spinner_src:
                break;
            }

        }

        @Override
        public void onPause() {
            super.onPause();
            myDbHelper.close();
        }

         @Override
            public void onResume() {
                super.onResume();
                myDbHelper.open();
            }



        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

            switch(arg1.getId()){
            case R.id.spinner_dest:
                spin_des = spinner_des.getSelectedItem().toString();
                //getStand(spin_src,spin_des);
                break;
            case R.id.spinner_src:
                spin_src = spinner.getSelectedItem().toString();
                break;
            }

        }


        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }

    }



    This is my BusDb.java file



    package play.adi.adj;

    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;
    import android.util.Log;

    public class BusDb {
        private static final String DB_NAME = "hello.db";

        private static String TABLE_NAME = "mydata";

        public static final String COLUMN_ID = "_id";
        private static final String BUS_STOP = "BUS_STOP";
        private static final String R1 = "R1";
        private static final String R2 = "R2";
        private static final String R3 = "R3";
        private static final String R4 = "R4";
        private static final String R5 = "R5";
        private static final String R6 = "R6";
        private static final String R7 = "R7";
        private static final String R8 = "R8";
        private static final String R9 = "R9";
        private static final String R10 = "R10";
        private static final int DATABASE_VERSION = 1;

        private DbHelper ourHelper;
        private final Context ourContext;
        private SQLiteDatabase ourDatabase;

        private static class DbHelper extends SQLiteOpenHelper {

            public DbHelper(Context context) {
                super(context, DB_NAME, null, DATABASE_VERSION);
                // TODO Auto-generated constructor stub
            }

            @Override
            public void onCreate(SQLiteDatabase db) {

                // TODO Auto-generated method stub

                db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + COLUMN_ID
                        + " INTEGER PRIMARY KEY AUTOINCREMENT, " + BUS_STOP
                        + " TEXT NOT NULL, " + R1 + " NUMERIC NOT NULL, " + R2
                        + " NUMERIC NOT NULL, " + R3 + " NUMERIC NOT NULL, " + R4
                        + " NUMERIC NOT NULL, " + R5 + " NUMERIC NOT NULL, " + R6
                        + " NUMERIC NOT NULL, " + R7 + " NUMERIC NOT NULL, " + R8
                        + " NUMERIC NOT NULL, " + R9 + " NUMERIC NOT NULL, " + R10
                        + " NUMERIC NOT NULL);");

            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                // TODO Auto-generated method stub
                db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
                onCreate(db);
            }

        }

        public BusDb(Context c) {
            ourContext = c;
        }

        public BusDb open() throws SQLException {
            ourHelper = new DbHelper(ourContext);
            ourDatabase = ourHelper.getWritableDatabase();
            return this;
        }

        public void close() {
            ourHelper.close();
        }

        public long createEntry(String name, byte r1[]) {
            // ,byte r2,byte r3,byte r4,byte r5,byte r6,byte r7,byte r8,byte r9,byte
            // r10

            ContentValues cv = new ContentValues();
            cv.put(BUS_STOP, name);
            cv.put(R1, r1[0]);
            cv.put(R2, r1[1]);
            cv.put(R3, r1[2]);
            cv.put(R4, r1[3]);
            cv.put(R5, r1[4]);
            cv.put(R6, r1[5]);
            cv.put(R7, r1[6]);
            cv.put(R8, r1[7]);
            cv.put(R9, r1[8]);
            cv.put(R10, r1[9]);
            /***
             * cv.put(R2, r2); cv.put(R3, r3); cv.put(R4, r4); cv.put(R5, r5);
             * cv.put(R6, r6); cv.put(R7, r7); cv.put(R8, r8); cv.put(R9, r9);
             * cv.put(R10, r10);
             **/

            return ourDatabase.insert(TABLE_NAME, null, cv);
        }

        public String[] routeSearch(String src, String des) throws SQLException {
            String[] columns = new String[] { COLUMN_ID, BUS_STOP, R1, R2, R3, R4,
                    R5, R6, R7, R8, R9, R10 };
            String[] answer = new String[5];
            // byte flag = 0;
            Cursor c = ourDatabase.query(TABLE_NAME, columns, BUS_STOP + "=?",
                    new String[]{src}, null, null, null,null);
            Cursor d = ourDatabase.query(TABLE_NAME, columns, BUS_STOP + "=?",
                    new String[]{des}, null, null, null,null);
            byte[] routes = new byte[10];
            if (c != null) {
                for (byte i = 0, j = 0; i < 10; i++) {
                    routes[i] = (byte) c.getInt(i + 2);
                    //Log.i(routes,"ERROR MESSAGE");
                    if (routes[i] == 1) {

                        if (d != null) {
                            if (d.getInt(i + 2) == 1) {
                                answer[j++] = columns[i + 2];
                                // flag++;
                            }

                        }
                    }
                }
                return answer;
            }
            return null;

        }
    }

1 个答案:

答案 0 :(得分:0)

在您的Activity类中,您尚未初始化 Button sqlGetInfo 。将其初始化为 -

sqlGetInfo = (Button) findViewById(R.id.button1);