Currently trying out Google's Places API and meanwhile trying to push a Place to my Firebase database. The code below tries to do that but errors out when it is called.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(this, data);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
String userUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference userRef = database.getReference("users/" + userUid);
userRef.setValue(place);
}
}
}
The error I get is as follows:
11-23 18:34:24.874 13155-13155/io.app.roomie E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.app.roomie, PID: 13155
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {io.app.roomie/io.app.roomie.MainActivity}: com.google.firebase.database.DatabaseException: Found conflicting getters for name: getAddress
at android.app.ActivityThread.deliverResults(ActivityThread.java:4089)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: com.google.firebase.database.DatabaseException: Found conflicting getters for name: getAddress
at com.google.android.gms.internal.zzamy$zza.<init>(Unknown Source)
at com.google.android.gms.internal.zzamy.zzj(Unknown Source)
at com.google.android.gms.internal.zzamy.zzca(Unknown Source)
at com.google.android.gms.internal.zzamy.zzbz(Unknown Source)
at com.google.firebase.database.DatabaseReference.zza(Unknown Source)
at com.google.firebase.database.DatabaseReference.setValue(Unknown Source)
at io.app.roomie.MainActivity.onActivityResult(MainActivity.java:81)
at android.app.Activity.dispatchActivityResult(Activity.java:6932)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4085)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Sorry about the code formatting. I couldn't get it to work otherwise.
The class com.google.android.gms.location.places.Place is not meant to be directly saved into Firebase.
You should write a simple POJO class that contains only the fields you need from Place, copy the data, and save this simple object into the database.
Related
I am on the Saved Games screen where is shows the list of all saves. When I select a saved game the app crashes with the error: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.games.snapshot.SnapshotMetadataEntity
It's basically the same code from here https://developers.google.com/games/services/android/savedgames?authuser=3&hl=sl
Please assist.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case RC_LIST_SAVED_GAMES:
if (resultCode == RESULT_OK) {
if (intent != null) {
if (intent.hasExtra(SnapshotsClient.EXTRA_SNAPSHOT_METADATA)) {
// Error occurs here when saved game is selected
SnapshotMetadata snapshotMetadata = intent.getParcelableExtra(SnapshotsClient.EXTRA_SNAPSHOT_METADATA);
assert snapshotMetadata != null;
sCurrentSaveName = snapshotMetadata.getUniqueName();
onLoadFromSnapshot(intent.getParcelableExtra(SnapshotsClient.EXTRA_SNAPSHOT_METADATA));
} else if (intent.hasExtra(SnapshotsClient.EXTRA_SNAPSHOT_NEW)) {
String unique = Long.toString(System.currentTimeMillis());
sCurrentSaveName = "snapshotH-" + unique;
onSaveSnapshot(null);
}
}
}
break;
}
}
This is what is shown in Logcat
2020-02-07 19:07:07.410 31988-31988/com.positivelymade.homeless2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.positivelymade.homeless2, PID: 31988
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9005, result=-1, data=Intent { (has extras) }} to activity {com.positivelymade.homeless2/com.positivelymade.homeless2.MainActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.games.snapshot.SnapshotMetadataEntity
at android.app.ActivityThread.deliverResults(ActivityThread.java:4605)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4647)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.games.snapshot.SnapshotMetadataEntity
at android.os.Parcel.readParcelableCreator(Parcel.java:2855)
at android.os.Parcel.readParcelable(Parcel.java:2781)
at android.os.Parcel.readValue(Parcel.java:2684)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3053)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:288)
at android.os.BaseBundle.unparcel(BaseBundle.java:232)
at android.os.BaseBundle.containsKey(BaseBundle.java:504)
at android.content.Intent.hasExtra(Intent.java:7923)
at com.positivelymade.homeless2.MainActivity.onActivityResult(MainActivity.java:222)
at android.app.Activity.dispatchActivityResult(Activity.java:7759)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4598)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4647)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
In my case, it is not working only in my release build since it is using pro guard. I solved it by adding pro guard configuration described here
I have this path in my firestore (com.google.android.gms.tasks.zzu#540f03f). How get image from storage use that path
This is the code that I am using
userImageRef= FirebaseStorage.getInstance().getReferenceFromUrl(MainActivity.avbUser.getProfilePic());
userImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
imgUrl=uri.toString();
}
});
The error that I get
Process: com.example.fastfoods, PID: 939
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fastfoods/com.example.fastfood.buyerhome}: java.lang.IllegalArgumentException: The storage Uri could not be parsed.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2576)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2658)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1492)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5737)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.IllegalArgumentException: The storage Uri could not be parsed.
at com.google.firebase.storage.FirebaseStorage.getReferenceFromUrl(com.google.firebase:firebase-storage##17.0.0:279)
at com.example.fastfood.buyerhome.onCreate(buyerhome.java:39)
at android.app.Activity.performCreate(Activity.java:6309)
I have an activity for capturing images with camera. After the snapshot, it is calling the following onActivityResult. I have an error when trying to decode the document (row marked with "ERROR HERE"). Some ideas of the reason? Thanks
Java
//if you capture image, convert to bitmap, show on screen and call readTextFromImage
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_PICTURE_CAPTURE) {
Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath()); // <--- ERROR HERE
bitmap = Helper.rotateBitmap(bitmap, pictureFile.getAbsolutePath());
image.setImageBitmap(bitmap);
} else if (requestCode == REQUEST_GET_SINGLE_FILE) {
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
} catch (Exception e) {
Log.d("Error Receipt: ", e.toString());
}
if (bitmap != null) {
image.setImageBitmap(bitmap);
}
}
//readTextFromImage();
}
}
Logcat
04-27 18:25:19.276 16179-16179/com.example.ves.gennaio3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ves.gennaio3, PID: 16179
java.lang.RuntimeException: Unable to resume activity {com.example.ves.gennaio3/com.example.ves.gennaio3.ReceiptActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=null} to activity {com.example.ves.gennaio3/com.example.ves.gennaio3.ReceiptActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3121)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=null} to activity {com.example.ves.gennaio3/com.example.ves.gennaio3.ReceiptActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:3720)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3107)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference
at com.example.ves.gennaio3.ReceiptActivity.onActivityResult(ReceiptActivity.java:184)
at android.app.Activity.dispatchActivityResult(Activity.java:6442)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3716)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3107)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Since you hasn't instantiated pictureFile, it is null by default.
Try
String pictureFile = data.getStringExtra("...","defaultPath");
and then you can use BitmapFactory.decodeFile...
If you declared pictureFile path before, then check your fileProvider.
Regards,
Csongi
I am beginner to android studio. Trying to put some hands on basic API call using Retrofit, for PHP API calls, for login. Sorry please correct me if my way of asking such question might be wrong.
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prefConfig = new PrefConfig(this);
apiInterface = ApiClient.getApiClient().create(ApiInterface.class); //Here
if (findViewById(R.id.fragment_container) != null) {
if (savedInstanceState != null) {
return;
}
if (prefConfig.readLoginStatus()) {
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new WelcomeFragment()).commit();
} else {
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new LoginFragment()).commit();
}
}
}
Everything goes fine when i comment the line labeled Here.
Error From The Log:
Process: com.example.surya.emorecomender, PID: 9729
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.surya.emorecomender/com.example.surya.emorecomender.MainActivity}: java.lang.IllegalArgumentException: baseUrl must end in /: http://10.0.2.2/database_api
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: http://10.0.2.2/database_api
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:513)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:456)
at com.example.surya.emorecomender.ApiClient.getApiClient(ApiClient.java:13)
at com.example.surya.emorecomender.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:6956)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
This is the most important part:
Process: com.example.surya.emorecomender, PID: 9729
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.surya.emorecomender/com.example.surya.emorecomender.MainActivity}: java.lang.IllegalArgumentException: baseUrl must end in /: http://10.0.2.2/database_api
Copy the java.lang.IllegalArgumentException: baseUrl must end in /: http://10.0.2.2/database_api and google it.
I used Firebase authentication in my Android application so when I press the button login when the text fields email and password are empty my application crash. I used Firebase version 10.0.1, This my code :
button_login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String email_et = mail_login_et.getText().toString();
final String password_et = pass_login_et.getText().toString();
mAuth.signInWithEmailAndPassword(email_et, password_et)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.d("LOGINACT", "signInWithEmail:onComplete:" + task.isSuccessful());
if (task.isSuccessful()) {
startActivity(new Intent(LoginActivity.this, MainActivity.class));
} else {
// startActivity(new Intent(LoginActivity.this, MainActivity.class));*
Log.w("LOGINACT", "signInWithEmail:failed", task.getException());
}
}
});
}
});
and this is the error log:
E/UncaughtException: java.lang.IllegalArgumentException: Given String is empty or null
at com.google.android.gms.common.internal.zzac.zzdv(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source)
at com.esprit.couverture4g.activities.LoginActivity$1.onClick(LoginActivity.java:83)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/art: Suspending all threads took: 25.358ms
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.esprit.couverture4g, PID: 3127
java.lang.IllegalArgumentException: Given String is empty or null
at com.google.android.gms.common.internal.zzac.zzdv(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source)
at com.esprit.couverture4g.activities.LoginActivity$1.onClick(LoginActivity.java:83)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)