0

Android(Eclipse)でアプリを作成するのは初めてです。現在、アカウント トラッカー アプリケーションを開発していますが、タブレットでアプリを開くと問題が発生しますが、Android エミュレーターでは正常に動作します。

エラーは次のとおりです: select * from table name のコンパイル時にそのようなテーブルはありません。

このエラーがタブレットでのみ発生し、Eclipse エミュレーターでは発生しない理由を教えてください。

これが私のコードです:

try
{
  db= SQLiteDatabase.openDatabase("sdcard/tracker.db",null,SQLiteDatabase.CREATE_IF_NECESSARY);
            Cursor c1 = db.rawQuery("select * from add_transaction",null);  
            int theTotal= c1.getCount();
            Toast.makeText(this, "Total: "+ theTotal, 1).show();
            String[] args= {"acc_no","trans_type","amount"};

  int acc_no_transCol= c1.getColumnIndex("acc_no");
  int trans_typeCol= c1.getColumnIndex("trans_type");
  int amountCol = c1.getColumnIndex("amount");
  TextView t1=null;


  while(c1.moveToNext()) {
    t1=new TextView(getApplicationContext());
    t1.setText("textbox");
    t1.setBackgroundColor(Color.parseColor("#ff009999"));
    l1.addView(t1);

    args[0] = Integer.toString((c1.getInt(acc_no_transCol)));
    args[1] = c1.getString(trans_typeCol);
    args[2] = Float.toString((c1.getFloat(amountCol)));

    t1.append("\nAccount Number: "+ args[0]+"\nTransaction Type: "+args[1]+"\nCurrent Balance: "+args[2]+"\n");
    //advance to the next record (first rec. if necessary)
  }
}  
catch (Exception e)
{
  Toast.makeText(getApplicationContext(),e.getMessage(), 
                  Toast.LENGTH_LONG).show();
}
4

1 に答える 1

0
package com.account;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
//import android.view.View;
//import android.view.View.OnClickListener;
import android.widget.*;

public class recent_trans extends Activity {
    TextView curr_user;
    //TextView data;
    Button logout, cancel;
    ImageButton home;
    SQLiteDatabase db;
    String[] name;
    LinearLayout l1;



     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.recent_trans);

            db = openOrCreateDatabase("tracker.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
            Toast.makeText(getApplicationContext(), "Database Is Created Successfully...", Toast.LENGTH_LONG).show();


           l1 = (LinearLayout)findViewById(R.id.layout1); 
           curr_user = (TextView)findViewById(R.id.lblcurrent_user);
           //data = (TextView)findViewById(R.id.txt1);
           home = (ImageButton)findViewById(R.id.img_btn_home);
           logout = (Button)findViewById(R.id.btnlogout);
           cancel = (Button)findViewById(R.id.btncancel);

            Intent myLocalIntent= getIntent();
            Bundle myBundle= myLocalIntent.getExtras();
            String v1 = myBundle.getString("uname");
            curr_user.setText(v1);

            db= SQLiteDatabase.openDatabase("sdcard/tracker.db",null,SQLiteDatabase.CREATE_IF_NECESSARY);
            **try
            {

                db.execSQL("CREATE TABLE add_transaction(acc_no INTEGER,trans_type TEXT,date DATE,amount FLOAT,cheque_no INTEGER,party_name VARCHAR(20),detail VARCHAR(200));");
                Toast.makeText(getApplicationContext(), "Table Is Created Successfully....", Toast.LENGTH_LONG).show();
            }
            catch(Exception ex)
            {
                Toast.makeText(getApplicationContext(), "Table Is Already Exists.....", Toast.LENGTH_LONG).show();
            }**

     try
     {


            //db = openOrCreateDatabase("tracker.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);


            Cursor c1 = db.rawQuery("select * from add_transaction",null);  
            int theTotal= c1.getCount();
            Toast.makeText(this, "Total: "+ theTotal, 1).show();
            String[] args= {"acc_no","trans_type","amount"};
            //Cursor c1= db.rawQuery(mySQL,null);

            int acc_no_transCol= c1.getColumnIndex("acc_no");
            int trans_typeCol= c1.getColumnIndex("trans_type");
            int amountCol = c1.getColumnIndex("amount");
            TextView t1=null;


            while(c1.moveToNext()) {


                    t1=new TextView(getApplicationContext());
                    t1.setText("textbox");
                    t1.setBackgroundColor(Color.parseColor("#ff009999"));
                    l1.addView(t1);


                args[0] = Integer.toString((c1.getInt(acc_no_transCol)));
                args[1] = c1.getString(trans_typeCol);
                args[2] = Float.toString((c1.getFloat(amountCol)));

                t1.append("\nAccount Number: "+ args[0]+"\nTransaction Type: "+args[1]+"\nCurrent Balance: "+args[2]+"\n");
            //advance to the next record (first rec. if necessary)
            }

     }  



     catch (Exception e)
     {
         Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG).show();
     }

    /* home.setOnClickListener(new OnClickListener(){

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

            Intent in = new Intent(getApplicationContext(), AccountTrackerActivity.class);
            startActivity(in);
            }
     });*/
     }







}
于 2013-04-06T05:25:07.933 に答える