Thursday, April 11, 2013

[android help] The name 'Assets' does not exist in the current context

android - The name 'Assets' does not exist in the current context - Stack Overflow




















I have a problem with this line of code. Want to create sqlite database on the device.



string dbPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\test.db";
if (!System.IO.File.Exists(dbPath))

using (System.IO.Stream sr = ***Assets***.Open("test.db"))
{
using (System.IO.Stream srTo = System.IO.File.Create(dbPath))
{
sr.CopyTo(srTo);
}
}


This message gives the: The name 'Assets' does not exist in the current context


























Change



Assets



to



getAssets().open("test.db")
























If you aren't doing this in an activity you need a reference to the Activity/Context. You will need to pass this in to your helper class in the constructor.



public yourClass(Activity context.......){

context.Assets.Open("your.db");
}



















lang-sql







.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...