آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

مشکل در خواندن دیتابیس

Salamon  11 سال پیش  11 سال پیش
+1 0

سلام.برنامه یک لیست ویو داره که از بانک تغذیه میشه.الان مشکلی که دارم اینه که همیشه در اولین اجرا که میخام لیست ویو رو برا اولین بار باز کنم  با ارور مواجه میشم.و متوجه شدم بانک کپی نمیشه ولی حجمش درسته وقتی داخل گوشی چک میکنم.ولی وقتی بار دوم برناه رو اجرا میکنم مشکل نداره و اطلاعات لود میشه ممنون میشم کمک کنید...سرچ کردم به نتیجه نرسیدم.اینم از کلاس G

public class G extends Application {

public static ArrayList<StructNote> notes = new ArrayList<StructNote>();
public static Activity currentactivity;
public static Context contex;
public static LayoutInflater inflater;
public static SQLiteDatabase database;
public static final String DIR_SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
public static final String DIR_DATABASE = DIR_SDCARD + "/database-Test/";


@Override
public void onCreate() {
super.onCreate();

contex = this.getApplicationContext();
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
new File(DIR_DATABASE).mkdirs();
database = SQLiteDatabase.openOrCreateDatabase(DIR_DATABASE + "/mydb.sqlite", null);
copyDataBase();
}


private void copyDataBase()
{
Log.i("Database",
"New database is being copied to device!");
byte[] buffer = new byte[1024];
OutputStream myOutput = null;
int length;
// Open your local db as the input stream
InputStream myInput = null;
try
{
myInput = G.contex.getAssets().open("mydb.sqlite");
// transfer bytes from the inputfile to the
// outputfile
myOutput = new FileOutputStream(DIR_DATABASE + "mydb.sqlite");
while ((length = myInput.read(buffer)) > 0)
{
myOutput.write(buffer, 0, length);
}
myOutput.close();
myOutput.flush();
myInput.close();
Log.i("Database",
"New database has been copied to device!");

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

 
 برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال 
Salamon  11 سال پیش
0 0

در ضمن اکتیویتی که از اون ایراد میگره هم میزارم.   میدهnullpointerexeption

 public class ActivityResult extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.result);
final TextView txtName = (TextView) findViewById(R.id.txtName);
final TextView txtInsta = (TextView) findViewById(R.id.txtInsta);
TextView txtFace = (TextView) findViewById(R.id.txtFace);
TextView txtWiki = (TextView) findViewById(R.id.txtWiki);
TextView txtWeb = (TextView) findViewById(R.id.txtWeb);
ImageView imgshow = (ImageView) findViewById(R.id.imgShow);
final ImageView imgFav = (ImageView) findViewById(R.id.imgFav);

imgFav.setOnClickListener(new OnClickListener(

) {

@Override
public void onClick(View arg0) {
Bundle extras = getIntent().getExtras();
int position = 0;
if (extras != null) {
position = extras.getInt("ID");
}

StructNote note = G.notes.get(position);
int idd = note.id;
String name = txtName.getText().toString();
Cursor cursor = G.database.rawQuery("SELECT * FROM dastanha WHERE onvan='" + name + "'", null);
while (cursor.moveToNext()) {
//String matn = cursor.getString(cursor.getColumnIndex("matn"));
// String id = cursor.getString(cursor.getColumnIndex("id"));

ContentValues cv = new ContentValues();
cv.put("fav", 1);

G.database.update("dastanha", cv, "id " + "=" + idd, null);

}
cursor.close();

}
});

txtInsta.setOnClickListener(new OnClickListener() {
 

@Override
public void onClick(View arg0) {
String instaLink = txtInsta.getText().toString();
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse(instaLink));
startActivity(myWebLink);

}
});

Bundle extras = getIntent().getExtras();
int position = 0;
if (extras != null) {
position = extras.getInt("ID");
}

StructNote note = G.notes.get(position);
txtName.setText(note.title);
String name = txtName.getText().toString();
Cursor cursor = G.database.rawQuery("SELECT * FROM dastanha WHERE onvan='" + name + "'", null);
while (cursor.moveToNext()) {
String matn = cursor.getString(cursor.getColumnIndex("matn"));
String tasvir = cursor.getString(cursor.getColumnIndex("tasvir"));
int fav = cursor.getInt(cursor.getColumnIndex("fav"));
txtInsta.setText(matn);
SetDrawable(tasvir, imgshow);
if (fav != 0) {
imgFav.setImageResource(R.drawable.favon);
} else {
imgFav.setImageResource(R.drawable.favoff);
}
}
cursor.close();
}


public static void SetDrawable(String tasvir, ImageView imgshow) {
int resID = G.contex.getResources().getIdentifier(tasvir, "drawable", G.contex.getPackageName());
imgshow.setImageResource(resID);
}

}

0 0
کسی نمیدونه مشکل کجاست؟ (11 سال پیش)
0 0
کمکککککککککککککککککککک (11 سال پیش)
0 0
کمکککککککککککککککککککک (11 سال پیش)
0 0
عجب پشتیبانی ای... (11 سال پیش)
0 0
منتظریم.ممنون اسپم میکنید...من جواب نگرفتم..حداقل یکی راهنمایی کنه گیر کردم... (11 سال پیش)
0 0
خیلی ممنون از مدیران فعال.حداقل یکی یک نگاه به این کد من بندازه بخدا ثواب داره.... (11 سال پیش)

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .