I am trying to call kotlin class function from Java class but getting error instead. I have added both kotlin and java code inside the java class. Below is the code and I am getting error while using context.
KotlinClass:
class TestDatabaseHandler(var context: Context?) :
SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION)
{
fun insertSerialNo(serialno: String)
{
val db=this.writableDatabase
var cv=ContentValues()
}
}
JavaClass:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String serialno =123456;
Intent intent = new Intent(MainActivity.this, Test.class);
intent.putExtra("serialno", serialno);
//Below Four lines of Code Error in JavaClass
var db= TestDatabaseHandler(this.applicationContext)
db.insertSerialNo(serialno)
//Java Conversion
String db= new TestDatabaseHandler(this.context);
db.insertSerialNo(serialno);
startActivity(intent);
}
}
Error:
1) Can't find symbol context
2) Can't resolve method insertSerialNo