Hi everyone I am new in Java programming and in the android studio environment and I need your help.
I am building an application that demands storing records of appointments into a database. I have created navigation between the activity's and I have also create a class named DBhandler
which is about create update and delete records so far so good but the moment I add the following part of code in the activity that is about to create a new row in the database:
DBHandler db = new DBHandler(this);
db.NewApointment(new Apointments(23123,text2,text3,text4,text5));
Intent sendIntent = new Intent(Create_Apointment.this, Records.class);
startActivity(sendIntent);
The application for some reason stops working. I did research for my problem but I did not found anything similar to my problem, could it be a bug of android studio or am I missing something? I will show you my whole code just make to easier to you
This is my main activity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void CreateApo(View view)
{
Intent i = new Intent(MainActivity.this, Create_Apointment.class);
startActivity(i);
}
public void Edit_Apointment(View v)
{
Intent intent = new Intent(MainActivity.this, Records.class);
startActivity(intent);
}
}
This is the activity which is used to store a new appointment
public class Create_Apointment extends AppCompatActivity {
EditText editText=(EditText) findViewById(R.id.editText);
EditText editText2=(EditText) findViewById(R.id.editText2);
EditText editText3=(EditText) findViewById(R.id.editText3);
EditText editText4=(EditText) findViewById(R.id.editText4);
String text2= editText.getText().toString();
String text3= editText2.getText().toString();
String text4= editText3.getText().toString();
String text5= editText4.getText().toString();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create__apointment);
}
public void back(View view)
{
Intent i = new Intent(Create_Apointment.this, MainActivity.class);
startActivity(i);
}
public void Create(View view)
{
DBHandler db = new DBHandler(this);
db.NewApointment(new Apointments(23123,text2,text3,text4,text5));
Intent sendIntent = new Intent(Create_Apointment.this, Katagrafes.class);
startActivity(sendIntent);
}
}
The following code is for the management of the database
public class DBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION=1;
//DATABASE NAME
private static final String DATABASE_NAME="APOINTMENTINFO";
private static final String APOINTMENT_TABLE="APOINTMENTS";
//Column NAMES
private static final String KEY_ID="id";
private static final String KEY_NAME="Name";
private static final String KEY_ADDRESS="Address";
private static final String KEY_PLACE="Place";
private static final String KEY_WRA="WRA";
public DBHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
String Create_APOINTMENTS_TABLE= "CREATE TABLE"+ APOINTMENT_TABLE + "(" + KEY_ID +"INTERGER PRIMARY KEY,"+ KEY_NAME + "TEXT," +KEY_ADDRESS + "TEXT," + KEY_PLACE+"TEXT,"+ KEY_WRA+"TEXT" + ")";
db.execSQL(Create_APOINTMENTS_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion)
{
db.execSQL("DROP TABLE IF EXISTS " + APOINTMENT_TABLE );
onCreate(db);
}
//add-insert new apointment
public void NewApointment(Apointments apointments)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values= new ContentValues();
values.put(KEY_NAME, apointments.getName()); //ONOMA RADEVOY
values.put(KEY_ADDRESS, apointments.getAddress());// adress
values.put(KEY_PLACE, apointments.getPlace());//meros
values.put(KEY_WRA, apointments.getWraRad());//wra
db.insert(APOINTMENT_TABLE, null ,values);
db.close();
}
// read 1 record
public Apointments getApointment(int id )
{
SQLiteDatabase db= this.getReadableDatabase();
Cursor cursor = db.query(APOINTMENT_TABLE, new String[]{KEY_ID, KEY_NAME,KEY_ADDRESS,KEY_PLACE,KEY_WRA},KEY_ID+"=?",new String[]{String.valueOf(id)},null,null,null,null );
if (cursor !=null)
cursor.moveToFirst();
Apointments contact = new Apointments(Integer.parseInt(cursor.getString(0)),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4));
//return apointment
return contact;
}
public List<Apointments> getAllApointments()
{
List<Apointments> apointmentsList= new ArrayList<Apointments>();
//selection of all querys
String selectQuery = "SELECT * FROM "+ APOINTMENT_TABLE;
SQLiteDatabase db= this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery,null);
if (cursor.moveToFirst())
{
do {
Apointments apointments = new Apointments(Integer.parseInt(cursor.getString(0)),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4));
}while (cursor.moveToNext());
}
return apointmentsList;
}
public int updateApointment(Apointments apointments)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME,apointments.getName());
values.put(KEY_ADDRESS,apointments.getName());
values.put(KEY_PLACE,apointments.getPlace());
values.put(KEY_WRA,apointments.getWraRad());
//update row
return db.update(APOINTMENT_TABLE,values, KEY_ID + " =?", new String[] {String.valueOf(apointments.getId())} );
}
//delete records
public void deleteapoitnments (Apointments apointments)
{
SQLiteDatabase db= this.getWritableDatabase();
db.delete(APOINTMENT_TABLE,KEY_ID+"=?", new String[]{String.valueOf(apointments.getId())} );
db.close();
}
}
Also I have create a class named "appointments
" to refer an appointment as an object in my application.
public class Apointments {
private int id;
private String Name;
private String Address;
private String Place;
private String WraRad;
public Apointments(int id, String Name, String Address, String Place, String WraRad )
{
this.id=id;
this.Name=Name;
this.Address=Address;
this.Place=Place;
this.WraRad=WraRad;
}
public void setId(int id) {
this.id = id;
}
public void setName(String Name) {
this.Name=Name;
}
public void setAddress(String Address) {
this.Address=Address;
}
public void setPlace(String Place) {
this.Place=Place;
}
public void setWraRad(String WraRad) {
this.WraRad=WraRad;
}
public int getId()
{
return id;
}
public String getName()
{
return Name;
}
public String getAddress()
{
return Address;
}
public String getPlace()
{
return Place;
}
public String getWraRad()
{
return WraRad;
}
}
My logCat says the following:
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0ac7 08-30 16:34:26.479 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getReferrer, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.479 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 74: Landroid/app/Activity;.getReferrer ()Landroid/net/Uri; 08-30 16:34:26.479 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0b3b 08-30 16:34:26.479 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.content.ContextWrapper.getSystemServiceName, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.479 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 517: Landroid/content/ContextWrapper;.getSystemServiceName (Ljava/lang/Class;)Ljava/lang/String; 08-30 16:34:26.479 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0bb8 08-30 16:34:26.479 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.isVoiceInteractionRoot, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 98: Landroid/app/Activity;.isVoiceInteractionRoot ()Z 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0be0 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.isDestroyed, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 93: Landroid/app/Activity;.isDestroyed ()Z 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0beb 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve check-cast 236 (Landroid/os/UserHandle;) in Lcom/example/dim/myapplication/Create_Apointment; 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0c3b 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.content.ContextWrapper.getExternalMediaDirs, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 504: Landroid/content/ContextWrapper;.getExternalMediaDirs ()[Ljava/io/File; 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0c68 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve check-cast 236 (Landroid/os/UserHandle;) in Lcom/example/dim/myapplication/Create_Apointment; 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0ca4 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getMediaController, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 68: Landroid/app/Activity;.getMediaController ()Landroid/media/session/MediaController; 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0cac 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.finishAffinity, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 48: Landroid/app/Activity;.finishAffinity ()V 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0cb2 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getSearchEvent, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 77: Landroid/app/Activity;.getSearchEvent ()Landroid/view/SearchEvent; 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0d2b 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/FragmentActivity;.onReallyStop ()V from Lcom/example/dim/myapplication/Create_Apointment;) 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.support.v4.app.FragmentActivity.onReallyStop, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 2396: Landroid/support/v4/app/FragmentActivity;.onReallyStop ()V 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0d6b 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.isVoiceInteraction, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 97: Landroid/app/Activity;.isVoiceInteraction ()Z 08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0ddb 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.requestVisibleBehind, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 169: Landroid/app/Activity;.requestVisibleBehind (Z)Z 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e40 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.shouldShowRequestPermissionRationale, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 199: Landroid/app/Activity;.shouldShowRequestPermissionRationale (Ljava/lang/String;)Z 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e55 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.onProvideAssistData, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 141: Landroid/app/Activity;.onProvideAssistData (Landroid/os/Bundle;)V 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e6a 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.finishAndRemoveTask, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 50: Landroid/app/Activity;.finishAndRemoveTask ()V 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e92 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.content.Context.getColor, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 425: Landroid/content/Context;.getColor (I)I 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0ee9 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.onNavigateUp, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 131: Landroid/app/Activity;.onNavigateUp ()Z 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0efa 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.reportFullyDrawn, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 167: Landroid/app/Activity;.reportFullyDrawn ()V 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0f17 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getParentActivityIntent, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 72: Landroid/app/Activity;.getParentActivityIntent ()Landroid/content/Intent; 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0f1d 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve check-cast 53 (Landroid/app/assist/AssistContent;) in Lcom/example/dim/myapplication/Create_Apointment; 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0f5b 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.finishAfterTransition, referenced from method com.example.dim.myapplication.Create_Apointment.access$super 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 49: Landroid/app/Activity;.finishAfterTransition ()V 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0f7f 08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getContentScene, referenced from method com.example.dim.myapplication.Create_Apointment.access$super FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.dim.myapplication/com.example.dim.myapplication.Create_Apointment}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) at android.app.ActivityThread.access$600(ActivityThread.java:128) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4517) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at android.support.v7.app.AppCompatDelegateImplBase.(AppCompatDelegateImplBase.java:68) at android.support.v7.app.AppCompatDelegateImplV7.(AppCompatDelegateImplV7.java:145) at android.support.v7.app.AppCompatDelegateImplV11.(AppCompatDelegateImplV11.java:28) at android.support.v7.app.AppCompatDelegateImplV14.(AppCompatDelegateImplV14.java:41) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:188) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:170) at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:502) at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:174) at com.example.dim.myapplication.Create_Apointment.(Create_Apointment.java:13) at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1319) at android.app.Instrumentation.newActivity(Instrumentation.java:1027) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) at android.app.ActivityThread.access$600(ActivityThread.java:128) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4517) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760) at dalvik.system.NativeStart.main(Native Method)
Any suggestions would be very helpful feel free to comment if something of my question is wrong Thanks in advance