Es wird die Fehlermeldung angezeigt, dass die App leider geschlossen ist, wenn ich von der AddReminder Aktivität zu der AddEventPlace Aktivität gehe.Android App Absturz auf Google Maps Aktivität
DataBaseHelper.java
public class DatabaseHelper extends SQLiteOpenHelper {
String tbl_User = "User";
String tbl_Reminder = "Reminder";
public static final String DATABASE_NAME = "Remind_Me.db";
public static final String COL_1 = "Username";
public static final String COL_2 = "Password";
public static final String COL_3 = "Email";
public static final String COL_4 = "Contact_No";
public static final String COL_5 = "ID";
public static final String COL_6 = "item";
public static final String COL_7 = "time";
public static final String COL_8 = "date";
public static final String COL_9 = "x_coordinates";
public static final String COL_10 = "y_coordinates";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists User (Username TEXT PRIMARY KEY ,Password TEXT, Email TEXT, Contact_No INTEGER)");
db.execSQL("create table Reminder (ID int PRIMARY KEY AUTOINCREMENT ," +
"item TEXT," +
" Time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
"Date DATETIME DEFAULT CURRENT_TIMESTAMP," +
" x_coordinates REAL," +
"y_coordinates REAL," +
"FOREIGN KEY(Username) REFERENCES User(USERNAME))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS User");
db.execSQL("DROP TABLE IF EXISTS Reminder");
onCreate(db);
}
public boolean insertUser(String Username, String password, String Email, int ContactNO) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1, Username);
contentValues.put(COL_2, password);
contentValues.put(COL_3, Email);
contentValues.put(COL_4, ContactNO);
long result = db.insert(tbl_User, null, contentValues);
if (result == -1)
return false;
else
return true;
}
public boolean AddReminder(String item, double x_coordinates, double y_coordinates, String Username) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_6, item);
contentValues.put(COL_7, " time('now') ");
contentValues.put(COL_8, java.lang.System.currentTimeMillis());
contentValues.put(COL_9, x_coordinates);
contentValues.put(COL_10, y_coordinates);
contentValues.put(COL_1, Username);
long result = db.insert(tbl_Reminder, null, contentValues);
if (result == -1)
return false;
else
return true;
}
}
AddReminder.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.champ.remindme2.AddReminder">
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:src="@drawable/remind_me_logo" />
<EditText
android:id="@+id/edtitem"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/plusButton"
android:layout_alignLeft="@+id/imageView6"
android:layout_alignTop="@+id/plusButton"
android:background="@drawable/rounded_edited_text"
android:inputType="text"
android:padding="5dp"
android:text="Add Item"
android:textAlignment="center" />
<Button
android:id="@+id/plusButton"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/NextButton"
android:layout_alignParentRight="true"
android:layout_alignStart="@+id/NextButton"
android:layout_below="@+id/imageView6"
android:background="@drawable/blue_botton"
android:onClick="plus"
android:text="+" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="47dp" />
<Button
android:id="@+id/NextButton"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/imageView6"
android:layout_alignTop="@+id/BackButton"
android:background="@drawable/blue_botton"
android:onClick="AddEventPlace"
android:text="Next" />
<Button
android:id="@+id/BackButton"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/edtitem"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/edtitem"
android:background="@drawable/blue_botton"
android:onClick="Back"
android:text="Back" />
</RelativeLayout>
AddReminder.java
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="380dp"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:id="@+id/Address"
android:layout_width="183dp"
android:layout_height="wrap_content"
android:layout_weight="0.98" />
<Button
android:id="@+id/Bsearch"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onSearch"
android:text="Search" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="382dp"
android:layout_height="383dp"
tools:context=".MapsActivity" />
</LinearLayout>
<Button
android:id="@+id/btnDone"
android:layout_width="137dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="Done"
android:text="Done" />
</LinearLayout>
AddEventplace.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="380dp"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:id="@+id/Address"
android:layout_width="183dp"
android:layout_height="wrap_content"
android:layout_weight="0.98" />
<Button
android:id="@+id/Bsearch"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onSearch"
android:text="Search" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="382dp"
android:layout_height="383dp"
tools:context=".MapsActivity" />
</LinearLayout>
<Button
android:id="@+id/btnDone"
android:layout_width="137dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="Done"
android:text="Done" />
</LinearLayout>
AddEventPlace.java
public class AddEventPlace extends FragmentActivity implements OnMapReadyCallback {
DatabaseHelper Db;
private GoogleMap mMap;
double Latitude;
double Longitude;
Button btnDone;
@Override
protected void onCreate(Bundle savedInstanceState) {
Db = new DatabaseHelper(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_event_place);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
btnDone = (Button) findViewById(R.id.btnDone);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
}
public void onSearch(View view) {
EditText location_tf = (EditText) findViewById(R.id.Address);
String location = location_tf.getText().toString();
List<Address> addressList = null;
if (location != null || !location.equals("")) {
Geocoder geocoder = new Geocoder(this);
try {
addressList = geocoder.getFromLocationName(location, 1);
} catch (IOException e) {
e.printStackTrace();
}
Address address = addressList.get(0);
LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
Latitude = address.getLatitude();
Longitude = address.getLongitude();
Latitude = 0.0;
Longitude = 0.0;
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
public void Done(View v) {
Intent intent = new Intent(this, Menu.class);
String Username = intent.getExtras().getString("Username");
String item = intent.getExtras().getString("item");
boolean isInserted = Db.AddReminder(item, Latitude, Longitude, Username);
if (isInserted == true) {
Toast.makeText(AddEventPlace.this, "Reminder is added", Toast.LENGTH_LONG).show();
intent.putExtra("Username", Username);
startActivity(intent);
} else
Toast.makeText(AddEventPlace.this, "Reminder is not added", Toast.LENGTH_LONG).show();
}
}
LogCat
05-12 11:54:20.249 2427-2427/com.example.champ.remindme2 E/libprocessgroup: failed to make and chown /acct/uid_10055: Read-only file system
05-12 11:54:20.311 2427-2435/com.example.champ.remindme2 E/art: Failed sending reply to debugger: Broken pipe
05-12 11:54:26.297 2427-2427/com.example.champ.remindme2 E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
05-12 11:54:26.298 2427-2427/com.example.champ.remindme2 E/GMPM: Scheduler not set. Not logging error/warn.
05-12 11:54:26.578 2427-2518/com.example.champ.remindme2 E/GMPM: Uploading is not possible. App measurement disabled
05-12 11:55:34.762 2427-2427/com.example.champ.remindme2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.champ.remindme2, PID: 2427
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4020)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4015)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
at com.example.champ.remindme2.AddEventPlace.Done(AddEventPlace.java:107)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4015)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-12 11:59:59.915 6972-6972/com.example.champ.remindme2 E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
05-12 11:59:59.917 6972-6972/com.example.champ.remindme2 E/GMPM: Scheduler not set. Not logging error/warn.
05-12 12:00:00.082 6972-7001/com.example.champ.remindme2 E/GMPM: Uploading is not possible. App measurement disabled
05-12 12:01:46.745 6972-6972/com.example.champ.remindme2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.champ.remindme2, PID: 6972
java.lang.IllegalStateException: Could not find method Back(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'BackButton'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:321)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:280)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-12 12:01:51.682 8463-8463/com.example.champ.remindme2 E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
05-12 12:01:51.683 8463-8463/com.example.champ.remindme2 E/GMPM: Scheduler not set. Not logging error/warn.
05-12 12:01:51.989 8463-8500/com.example.champ.remindme2 E/GMPM: Uploading is not possible. App measurement disabled
fügen Fehlerprotokoll hinzu, damit wir Fehlerursache sehen können. – androidnoobdev
Ich habe die Nachprüfung aktualisiert. –