I had a sample app in android version 4.2. I had set Breakpoints for each and every line. At the time of debugging, suddenly the debugging stopped saying that "The source attachment does not contain the source for the file SQLiteOpenHelper.class".
I attached the jar file and still it reports the error. Installed everything currently. But dont know the cause for this error.
This is my MainActivity.java
package com.example.newwaterreadingapp;
import java.util.Calendar;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
protected static final android.content.Context Context = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RelativeLayout mainLayout=(RelativeLayout)findViewById(R.id.mainLayout);
mainLayout.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
final LinearLayout readingLayout=(LinearLayout)findViewById(R.id.waterReading);
readingLayout.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
final LinearLayout pastDatePickerLayout=(LinearLayout)findViewById(R.id.PastDatePickerLayout);
pastDatePickerLayout.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
readingLayout.setVisibility(View.GONE);
pastDatePickerLayout.setVisibility(View.GONE);
Button AddWaterReading=(Button)findViewById(R.id.AddWaterReading); //click on + button.
AddWaterReading.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
readingLayout.setVisibility(View.VISIBLE);
mainLayout.setVisibility(View.GONE);
TextView txtgetCurrentDate=(TextView)findViewById(R.id.currentDate);
final Calendar c=Calendar.getInstance();
txtgetCurrentDate.setText((c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.DATE)+"/"+c.get(Calendar.YEAR));
}
});
TextView getPastDate=(TextView)findViewById(R.id.getDate);
getPastDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
readingLayout.setVisibility(View.GONE);
pastDatePickerLayout.setVisibility(View.VISIBLE);
}
});
Button savePastDate=(Button)findViewById(R.id.savePastDate);
savePastDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pastDatePickerLayout.setVisibility(View.GONE);
readingLayout.setVisibility(View.VISIBLE);
DatePicker getPastDatepicker=(DatePicker)findViewById(R.id.getPastDate);
int YY=getPastDatepicker.getYear();
int MM=getPastDatepicker.getMonth();
int DD=getPastDatepicker.getDayOfMonth();
TextView getPastDate=(TextView)findViewById(R.id.getDate);
getPastDate.setText((MM+1)+"/"+DD+"/"+YY);
}
});
Button saveWaterReadingToDB=(Button)findViewById(R.id.saveWaterReading);
saveWaterReadingToDB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
readingLayout.setVisibility(View.GONE);
mainLayout.setVisibility(View.VISIBLE);
TextView getPastDate=(TextView)findViewById(R.id.getDate);
TextView txtgetCurrentDate=(TextView)findViewById(R.id.currentDate);
TextView txtgetWaterReading=(TextView)findViewById(R.id.water_Reading);
CreateDB helper =new CreateDB(Context, "WaterElectricityReading.db", null, 1);
SQLiteDatabase DB;
DB=helper.getWritableDatabase();
String pastDate=getPastDate.getText().toString().trim();
String currentDate=txtgetCurrentDate.getText().toString().trim();
String waterReading=txtgetWaterReading.getText().toString().trim();
ContentValues values=new ContentValues();
values.put(CreateDB.COLUMN_NAME_READING_MODE,"Water");
values.put(CreateDB.COLUMN_NAME_PASTDATETIME, pastDate);
values.put(CreateDB.COLUMN_NAME_CURRENTDATETIME, currentDate);
values.put(CreateDB.COLUMN_NAME_READINGVALUE, waterReading);
DB.insert(CreateDB.TABLE_NAME, null, values);
Toast.makeText(getApplicationContext(), "Added", Toast.LENGTH_LONG).show();
DB.close();
helper.close();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
and CreateDB.java
package com.example.newwaterreadingapp;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class CreateDB extends SQLiteOpenHelper{
private static final String DATABASE_NAME="WaterElectricityReading.db";
public static final String TABLE_NAME="Reading";
public static final String COLUMN_NAME_READING_ID="_Id";
public static final String COLUMN_NAME_READING_MODE="ReadingMode";
public static final String COLUMN_NAME_PASTDATETIME="PastDateTime";
public static final String COLUMN_NAME_CURRENTDATETIME="CurrentDateTime";
public static final String COLUMN_NAME_READINGVALUE="ReadingValue";
public static final int DATABASE_VERSION = 1;
public static String DB_PATH = "";
public CreateDB(Context context,String name, CursorFactory factory,
int version) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase DB){
final String CREATE_TABLE="create table if not exists "+ TABLE_NAME + "("+ COLUMN_NAME_READING_ID +" integer primary key autoincrement,"
+COLUMN_NAME_READING_MODE+" text not null,"+COLUMN_NAME_PASTDATETIME+" date not null,"+COLUMN_NAME_CURRENTDATETIME
+" date not null,"+COLUMN_NAME_READINGVALUE+" integer not null"+");";
DB.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
Could anyone please suggest where I went wrong.
Thanks.