Call method from other class in different .java file
<p>I tried to call the method of another class, it is in the same package but when I test it on my phone, it will force close.</p>

<p>basically I create an object of LocalSQLite class, sqlite and use sqlite.method()
below is my code:</p>

<p><strong>Sqlitetest2Activity.java</strong></p>

<pre><code>package com.test.test;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class Sqlitetest2Activity extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    LocalSQLite sqlite = new LocalSQLite();
    sqlite.createTable();        
    }
}
</code></pre>

<p><strong>LocalSQLite.java</strong></p>

<pre><code>package com.test.test;

import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

public class LocalSQLite extends Activity {
    SQLiteDatabase mydb;
    private static String DBNAME = "city.db";    // SQLITE DATABASE FILE NAME.
    private static String TABLE = "citytable";       // TABLE NAME

/* CREATE TABLE IF NOT EXISTS */
public void createTable(){
    try{
    mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    mydb.execSQL("CREATE TABLE IF  NOT EXISTS "+ TABLE +" (ID INTEGER PRIMARY KEY, CITY TEXT);");
    mydb.close();
    }catch(Exception e){
        Toast.makeText(getApplicationContext(), "Error in creating table", Toast.LENGTH_LONG);
    }
}

/* DROPS TABLE */
public void dropTable(){
    try{
        mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
        mydb.execSQL("DROP TABLE " + TABLE);
        mydb.close();
    }catch(Exception e){
        Toast.makeText(getApplicationContext(), "Error encountered while dropping table.", Toast.LENGTH_LONG);
    }
}

/* THIS FUNCTION INSERTS DATA TO THE DATABASE */
public void insertIntoTable(String city_id, String city_name){
    try{
        mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
        mydb.execSQL("INSERT INTO " + TABLE + "(ID, CITY) VALUES('"+city_id+"','"+city_name+"')");
        mydb.close();
    }catch(Exception e){
        Toast.makeText(getApplicationContext(), "Error in inserting into table", Toast.LENGTH_LONG);
    }
}
}
</code></pre>
