Wow. What a crash.

Ok, let's see.

Your JavaScript callback needs a reference to Activity, to use with database stuff (actually, a reference to Context, which is a base class of Activity).

Do not extend JS callback from "test".

Pass a reference to your activity into the JS callback constructor. You are already doing this.

Save it as a member variable in the JS callback. Finally, use that member variable with DB stuff.

-- Kostya

17.12.2010 11:45, cuil yahoo пишет:
Thanks for replying so quickly.

On Fri, Dec 17, 2010 at 1:59 PM, Kostya Vasilyev <[email protected] <mailto:[email protected]>> wrote:

    What is the output of logcat under "Caused by:" ?


I see no "Caused by" in the logcat output, here is the complete output http://pastebin.com/VMsrK0Db


    And don't extend your JavaScript callback from "test".

    Activities represent "UI screens" and are managed by Android.
    Defining and instantiating one yourself, bypassing the framework,
    is a recipe for disaster.

Sorry, i am new to developing for android, what exactly do you mean ? What could be a walk around?

Cuil

    -- Kostya

    17.12.2010 11:14, cuil yahoo пишет:
    This thing has started to irritate me,
    I have copied the code below,


    this is test.java, the main class of my program.

    package android.test;


    import android.app.Activity;
    import android.content.ContentValues;
    import android.database.sqlite.*;
    import android.os.Bundle;
    import android.util.*;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import seeta.socialcalc.R;

    class JavaScriptInterface extends test{
        String saveme;
    public JavaScriptInterface(test test) {
            // TODO Auto-generated constructor stub
        }

    public void gotit(String s)
    {
    saveme=s;
    final String got="gotit";
    insertvalues(s);
    Log.d(got, s);
    }



    private void insertvalues(String s)
    {
        databaseopener dataBasehelper = new databaseopener(this);
        SQLiteDatabase db = dataBasehelper.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(databaseopener.data, "data");
    db.insert("textdata", databaseopener.data, cv);
        db.close();

    }

    }

    public class test extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            Log.d("test" , "got till here1");
            WebView web = (WebView) findViewById(R.id.webView);
            web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
            web.getSettings().setPluginsEnabled(false);
            web.getSettings().setSupportMultipleWindows(false);
            web.getSettings().setSupportZoom(false);
            web.setVerticalScrollBarEnabled(false);
            web.setHorizontalScrollBarEnabled(false);
            web.addJavascriptInterface(new JavaScriptInterface(this),
    "Android");

            //Our application's main page will be loaded
            web.loadUrl("file:///android_asset/index.html");

            web.setWebViewClient(new WebViewClient() {
                @Override public boolean
    shouldOverrideUrlLoading(WebView view, String url) {
                    return false;
                }
            });
        }
    }


    The next class helps implement databases,


    package android.test;

    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteDatabase.CursorFactory;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.database.SQLException;





    public class databaseopener extends SQLiteOpenHelper
    {

        private static final String database_name = "mydatabase.db";
        static String data = "Data";



    public databaseopener(Context context)
    {
        super(context, database_name, null, 1);
            // TODO Auto-generated constructor stub

        }
    @Override
        public void onCreate(SQLiteDatabase db) {

        android.util.Log.d("database", "database about to be created");
        db.execSQL( "CREATE TABLE textdata (_id INTEGER PRIMARY KEY
    AUTOINCREMENT, data TEXT);");
            // TODO Auto-generated method stub

        }

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

            // i don't want to upgrade right now, first want the
    database to be created.
            // TODO Auto-generated method stub

        }

    }


    Any Pointers on errors would be appreciated.

    Cuil


    On Fri, Dec 17, 2010 at 1:34 PM, Kostya Vasilyev
    <[email protected] <mailto:[email protected]>> wrote:

        It looks like a problem in your JavaScriptInterface.insertValues.

        There should be more in the logcat below what you posted,
        starting with "Caused by:".

        -- Kostya


        17.12.2010 10:31, cuil yahoo пишет:
        I went through some online material both blogs and videos,
        and managed to rectify the code. However, now i get a
        NullPointerException,

        12-17 12:48:44.184: INFO/dalvikvm(327):     at
        
android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
        12-17 12:48:44.194: INFO/dalvikvm(327):     at
        
android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
        12-17 12:48:44.194: INFO/dalvikvm(327):     at
        android.test.JavaScriptInterface.insertvalues(test.java:32)
        12-17 12:48:44.224: INFO/dalvikvm(327):     at
        android.test.JavaScriptInterface.gotit(test.java:23)
        12-17 12:48:44.224: INFO/dalvikvm(327):     at
        android.webkit.WebViewCore.nativeTouchUp(Native Method)
        12-17 12:48:44.224: INFO/dalvikvm(327):     at
        android.webkit.WebViewCore.nativeTouchUp(Native Method)
        12-17 12:48:44.244: INFO/dalvikvm(327):     at
        android.webkit.WebViewCore.access$3300(WebViewCore.java:52)
        12-17 12:48:44.254: INFO/dalvikvm(327):     at
        
android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1150)
        12-17 12:48:44.264: INFO/dalvikvm(327):     at
        android.os.Handler.dispatchMessage(Handler.java:99)
        12-17 12:48:44.304: INFO/dalvikvm(327):     at
        android.os.Looper.loop(Looper.java:123)
        12-17 12:48:44.304: INFO/dalvikvm(327):     at
        android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:621)
        12-17 12:48:44.334: INFO/dalvikvm(327):     at
        java.lang.Thread.run(Thread.java:1096)


        It would be helpful if someone could provide some pointers
        to handle this. I could use catch and finally blocks, but
        the database should open atleast.

        Thanks.

        Cuil



        On Thu, Dec 16, 2010 at 6:23 PM, cuil yahoo
        <[email protected] <mailto:[email protected]>> wrote:

            Hello,

            I am trying to use a database to store a huge text in it
            serially(using a primary key, for easy searching).

            I have already done the following things,

            1. Created a SQLite database(named database) using the
            SQLite Database Browser, and have imported that to my
            assets folder in Eclipse. The database has two fields
            one _id(primarykey) and saveme(the text field).

            2. Now, i want to write stuff in this database, however
            when i try to open the database using the code below, i
            get a SQLite Code 14 type of an error( which on a google
            result showed up error on opening of database).

            SQLiteDatabase writedatabase = null;
            writedatabase.openDatabase("file:///android_asset/database",null,0);
            writedatabase.execSQL("INSERT INTO " + "database" + "
            Values ('1', 'first')");


            It would be really very helpful, if someone could please
            point the error in the steps.

            Thanks.

            Cuil



-- You received this message because you are subscribed to the
        Google
        Groups "Android Developers" group.
        To post to this group, send email to
        [email protected]
        <mailto:[email protected]>
        To unsubscribe from this group, send email to
        [email protected]
        <mailto:[email protected]>
        For more options, visit this group at
        http://groups.google.com/group/android-developers?hl=en


-- Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com

-- You received this message because you are subscribed to the
        Google
        Groups "Android Developers" group.
        To post to this group, send email to
        [email protected]
        <mailto:[email protected]>
        To unsubscribe from this group, send email to
        [email protected]
        <mailto:android-developers%[email protected]>
        For more options, visit this group at
        http://groups.google.com/group/android-developers?hl=en


-- You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to
    [email protected]
    <mailto:[email protected]>
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:[email protected]>
    For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


-- Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com

-- You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to
    [email protected]
    <mailto:[email protected]>
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:android-developers%[email protected]>
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to