Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am developing an android app in which i created one activity, in that activity two textviews i have kept shown just below the line //Session For select_category page in Activity.java :

Previously i had set on this textview the date and time, but now i am fetching value from database that is name of mandali from getMandaliName() method and trying to keep that on this textview, then also it is still showing the date and time that i set before.I don't know why it is showing previously set data on the textview instead of showing the fetched data on textview. My Activity.java is here:

package com.bis.localsale;
import java.security.PublicKey; 
import com.bis.localsale.util.CommonUtil;
import com.bis.localsale.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class SelectCategory extends Activity {
                public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.select_category);

            DBHelper db = new DBHelper(this);
            Button btnMandaliName = (Button) findViewById(R.id.mandali_name);
            final String mandali = db.getMandaliName();
            System.out.println(mandali);
            Toast.makeText(getApplicationContext(),mandali,
                    Toast.LENGTH_SHORT).show();
            btnMandaliName.setText(mandali);

                //Session For select_category page
            TextView txtSession = (TextView) findViewById(R.id.txtSession);
            txtSession.setText(mandali);
            TextView textTime = (TextView) findViewById(R.id.txtTime);
            textTime.setText(mandali);

            DisplayMetrics dmAdmin =new DisplayMetrics();
            WindowManager windowManager = (WindowManager)     this.getSystemService(this.WINDOW_SERVICE);
            Display display = windowManager.getDefaultDisplay();
             int width = display.getWidth(); 
             int height = display.getHeight();

            final EditText editTextLitre = (EditText)  findViewById(R.id.edit_text_litre);
            editTextLitre.setInputType(InputType.TYPE_CLASS_NUMBER);
            final TextView tvwAmount = (TextView)findViewById(R.id.amount);
            editTextLitre.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub
                    if(s.length()>0){
                        if(s.length()<5){
                        String text = String.valueOf(Float.valueOf(s.toString())*10); 
                        tvwAmount.setText(text);

                        Toast.makeText(getApplicationContext(),
                                mandali,
                                Toast.LENGTH_SHORT).show();

                        }
                        else{
                            InputFilter[] FilterArray = new InputFilter[0];
                            FilterArray[0] = new InputFilter.LengthFilter(4);
                            editTextLitre.setFilters(FilterArray);
                            /*editTextLitre.setText(s.subSequence(0, 4));*/

                        }

                    }
                    else{
                    tvwAmount.setText("0");
                    }
                }


                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub

                }
            });


                Button btnSaveDetails = (Button) findViewById(R.id.btnSave);


}

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater(); 
        menuInflater.inflate(R.menu.select_category_menu, menu);
        return true;

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.admin:
            Intent intent1 = new Intent("com.example.localsale.Admin");
            startActivity(intent1);
            return true;
        default:
            return super.onOptionsItemSelected(item);

        }

    }



}

My database helper class is shown with code below
My DBHelper.java is here:

package com.bis.localsale;
import java.io.IOException;
import android.annotation.SuppressLint;
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 DBHelper extends SQLiteOpenHelper
{
        private SQLiteDatabase db;
    public static final String KEY_ROWID = "_id";
    public static final String KEY_CREATED_USER = "createdUser";
    public static final String KEY_CREATED_DATE = "createdDate";
    public static final String KEY_LAST_MODIFIED_USER= "lastModifiedUser"; 
    public static final String KEY_LAST_MODIFIED_DATE= "lastModifiedDate";
    public static final String KEY_RECORD_STATUS = "recordStatus";
    public static final String KEY_NAMEOFMANDALI = "nameOfMandali";
    public static final String KEY_RATEOFCOW = "rateOfCow";
    public static final String KEY_RATEOFBUFFALO = "rateOfBuffalo";


    DBHelper DB = null;
    private static final String DATABASE_NAME = "localsale.db";
    private static final int DATABASE_VERSION = 1;
    public static final String DATABASE_TABLE_NAME = "organizationSetup";

    private static final String DATABASE_TABLE_CREATE = "CREATE TABLE "
            + DATABASE_TABLE_NAME
            + "("
            + "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
            + "nameOfMandali TEXT NOT NULL, rateOfCow TEXT NOT NULL, rateOfBuffalo TEXT NOT NULL, createdUser TEXT NOT NULL, createdDate TEXT NOT NULL, lastModifiedUser TEXT NOT NULL, lastModifiedDate TEXT NOT NULL, recordStatus TEXT NOT NULL);";

    public DBHelper(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {

        try {

            db.execSQL(DATABASE_TABLE_CREATE);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
         // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_CREATE);

        // Create tables again
        onCreate(db);
    }

     public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            onUpgrade(db, oldVersion, newVersion);
        }


    public Cursor rawQuery(String string, String[] strings) {
        // TODO Auto-generated method stub
        return null;
    }

    public SQLiteDatabase open() {

        SQLiteDatabase db = this.getWritableDatabase(); 
        return db;
    }

    public Cursor getDetails(String text) throws SQLException {

        Cursor mCursor = db.query(DATABASE_TABLE_NAME, new String[] {
                KEY_ROWID, KEY_CREATED_USER, KEY_CREATED_DATE, KEY_LAST_MODIFIED_USER, KEY_LAST_MODIFIED_DATE,
                KEY_RECORD_STATUS }, null, null, null, null,
                null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }


    public void insert(String DATABASE_TABLE_NAME, Object object,
            ContentValues values) {
        // TODO Auto-generated method stub


    }

@SuppressLint("NewApi")
public String getMandaliName(){
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.rawQuery(DATABASE_TABLE_NAME, new String[]
            { KEY_NAMEOFMANDALI}, null);
    if (cursor != null)
        cursor.moveToLast();
    String mandaliName = cursor.getString(cursor.getColumnIndex(KEY_NAMEOFMANDALI));
    Log.e("test", mandaliName);
    return mandaliName;

} }

I am not getting that what is the error in the code that it(fetched data) is not getting displayed on the textview. Please help me with this by providing answer as soon as possible.

share|improve this question
 
are you sure that your database is being populated correctly? –  Rohan Kandwal Dec 21 '13 at 10:38
 
Show the actual error message. –  CL. Dec 21 '13 at 11:29
add comment

1 Answer

Can't tell what your question is as your descrption is confusing but if your error is

android.database.sqlite.SQLiteException near DATABASE_TABLE_NAME syntax error(code:1) while compiling organizationSetup

Try putting a space after the table name. Your brackets are touching the table name.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.