I have a problem with storing data in the Firebase Realtime Database. There are no errors but nothing is stored in the database. I have tried with different guides, tutorial (on yt) posts (found here) but none of them worked. Is there a working way that allows me to solve this problem? Thanks in advance everyone and sorry if my English is not perfect.
public void registration() {
if(!validation())
return;
final ProgressDialog progressDialog = new ProgressDialog(RegisterActivity.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Creating account...");
progressDialog.show();
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
DatabaseReference reff = mDatabase.getReference();
user = new User();
String tableName = "Users";
Map<String, String> userMap = new HashMap<String, String>();
//register user in firebase
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
user.setUser(mFullName.getText().toString().trim());
user.setEmail(mEmail.getText().toString().trim());
userMap.put(fullName, email);
String currentUser = mAuth.getCurrentUser().getUid();
reff.child(tableName).child(currentUser).setValue(userMap);
//The following line make app crush
reff.setValue(userMap, new Firebase.CompletionListener() {
#Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
if (firebaseError != null) {
System.out.println("Data could not be saved. " + firebaseError.getMessage());
} else {
System.out.println("Data saved successfully.");
}
}
});
Toast.makeText(RegisterActivity.this, "User successful created", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), MenuActivity.class));
finish();
progressDialog.dismiss();
}
else {
Toast.makeText(RegisterActivity.this, "Error! " +
task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
User.java
public class User {
private String user, email, photoUrl, Uid;
public User() { }
public User(String uid, String user) {
Uid = uid;
this.user = user;
}
public User(String user) {
this.user = user;
}
public User(String user, String email, String photoUrl, String uid) {
this.user = user;
this.email = email;
this.photoUrl = photoUrl;
Uid = uid;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
public String getUid() {
return Uid;
}
public void setUid(String uid) {
Uid = uid;
}
}
The error is:
com.google.firebase.database.DatabaseException: Failed to parse node with class class com.example.xxxxxxxx.activities.RegisterActivity$4$1
at com.google.firebase.database.snapshot.NodeUtilities.NodeFromJSON(NodeUtilities.java:103)
at com.google.firebase.database.snapshot.NodeUtilities.NodeFromJSON(NodeUtilities.java:28)
at com.google.firebase.database.snapshot.PriorityUtilities.parsePriority(PriorityUtilities.java:39)
at com.google.firebase.database.DatabaseReference.setValue(DatabaseReference.java:199)
at com.example.xxxxxxxx.activities.RegisterActivity$4.onComplete(RegisterActivity.java:160)
at com.google.android.gms.tasks.zzj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
logcat:
2021-01-02 17:07:36.549 20191-20213/com.example.inbioaiqua W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-01-02 17:07:36.557 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.562 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.574 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.580 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.592 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.601 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.611 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.617 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.625 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.631 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.639 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.645 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.657 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.663 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.673 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.680 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.689 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.693 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.706 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.713 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.722 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.729 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.738 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.849 20191-20213/com.example.inbioaiqua D/FirebaseAuth: Notifying id token listeners about user ( 7LOLWRPcBhVqHm98BVHzpI5FkDG2 ).
2021-01-02 17:07:36.849 20191-20213/com.example.inbioaiqua D/FirebaseAuth: Notifying auth state listeners about user ( 7LOLWRPcBhVqHm98BVHzpI5FkDG2 ).
2021-01-02 17:07:36.874 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:37.046 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:37.260 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:37.260 20191-20214/com.example.inbioaiqua W/OpenGLRenderer: Points are too far apart 4.000001
So in your code:
reff.child(tableName).setValue(user)
Here you are trying to set a value for a node that already has branches and Firebase database does not allow that, so what you can do is create another node in the "Users" table to store users. For example:
reff.child(tableName).child("User1"). setValue(user);
Here "User1" is just to label the field and can be a simple integer such as "1" too.
Your code:
reff.setValue(userMap, new Firebase.CompletionListener()
Again, you are trying to set a value of a node with branches which in your case it's the main branch and Firebase database don't allow that. So what you can do is create another node in the reff.
reff.child(tableName).child(YOUR_DESIRED_CHILD).setValue(userMap).addOnCompleteListener(new OnCompleteListener<Void>()
Here YOUR_DESIRED_CHILD is field name for your Users childs.
And it should work just fine.
You are passing to the "setValue()" method a CompletionListener object, an option which is not available anymore. To add the user, please use the following lines of code:
reff.setValue(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d("TAG", "User added successfully!");
} else {
Log.d("TAG", task.getException().getMessage()); //Don't ignore potential errors!
}
}
});
And comment or remove the lines that you are using now.
Your DatabaseReference is not initialized, so use the below code on top.
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
DatabaseReference reff = mDatabase.getReference();
And add onComplete listener to setValue().
reff.child(tableName)
.child(currentUser)
.setValue(userMap, new Firebase.CompletionListener() {
#Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
if (firebaseError != null) {
System.out.println("User data save failure." + firebaseError.getMessage());
} else {
System.out.println("User data save successful.");
progressDialog.dismiss();
startActivity(new Intent(getApplicationContext(), MenuActivity.class));
finish();
}
}
});
I am using camera2 api and it is working fine on pre Pie android version but it is showing white screen when opening camera on android pie devices. I have checked on emulator, A10 devices.
Kindly help me
app build.gradle
compileSdkVersion 29
defaultConfig {
applicationId "xxx.xxx.xxx.xxx"
minSdkVersion 23
targetSdkVersion 29
}
I have also declared permissions
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera2.full" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Here is the logs:
2020-01-06 21:43:04.354 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:04.960 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=1246ms; Flags=1, IntendedVsync=863946795696, Vsync=864596795670, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=864606099000, AnimationStart=864606243100, PerformTraversalsStart=864606749200, DrawStart=865124397700, SyncQueued=865125104600, SyncStart=865126372900, IssueDrawCommandsStart=865126580100, SwapBuffers=865128343100, FrameCompleted=865194693500, DequeueBufferDuration=135000, QueueBufferDuration=1984000,
2020-01-06 21:43:04.995 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:05.037 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:05.094 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:05.229 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=853ms; Flags=0, IntendedVsync=864625292593, Vsync=865241959235, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=865246522400, AnimationStart=865246651100, PerformTraversalsStart=865257381400, DrawStart=865345430100, SyncQueued=865345513800, SyncStart=865347226700, IssueDrawCommandsStart=865347728400, SwapBuffers=865348734300, FrameCompleted=865480205200, DequeueBufferDuration=5031000, QueueBufferDuration=9624000,
2020-01-06 21:43:05.256 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:08.829 4923-5340/com.iris.idrs.smartcapture I/CConversion: Creating output document: /data/user/0/com.iris.idrs.smartcapture/cache/temp/output.pdf
2020-01-06 21:43:08.899 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:08.965 4923-5012/com.iris.idrs.smartcapture D/OpenGLRenderer: endAllActiveAnimators on 0xbbc70100 (RippleDrawable) with handle 0xbfb7f490
2020-01-06 21:43:09.018 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:13.564 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:16.035 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:16.352 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.353 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.394 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.424 4923-4923/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) identical 1 line
2020-01-06 21:43:16.425 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.474 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.602 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.878 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=1553ms; Flags=1, IntendedVsync=875568052075, Vsync=876284718713, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=876287357500, AnimationStart=876287533900, PerformTraversalsStart=876287961000, DrawStart=876918332800, SyncQueued=876919028800, SyncStart=876926725800, IssueDrawCommandsStart=876946153900, SwapBuffers=876951883200, FrameCompleted=877129627800, DequeueBufferDuration=132000, QueueBufferDuration=1326000,
2020-01-06 21:43:16.880 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 48 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:17.027 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:31.548 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:43:31.551 4923-4961/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) FinalizerDaemon identical 7 lines
2020-01-06 21:43:31.552 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:43:42.533 4923-4923/com.iris.idrs.smartcapture W/ViewRootImpl[CConversionActivity]: Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=902633, downTime=902633, deviceId=-1, source=0x101 }
2020-01-06 21:43:43.110 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:43.283 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=1026ms; Flags=1, IntendedVsync=902505438851, Vsync=902772105507, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=902785072800, AnimationStart=902785162200, PerformTraversalsStart=902785352700, DrawStart=903355162800, SyncQueued=903361009100, SyncStart=903363119200, IssueDrawCommandsStart=903363531400, SwapBuffers=903370175800, FrameCompleted=903534179400, DequeueBufferDuration=64210000, QueueBufferDuration=23339000,
2020-01-06 21:43:43.283 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:43.287 4923-4923/com.iris.idrs.smartcapture W/ViewRootImpl[CConversionActivity]: Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x68, repeatCount=0, eventTime=902692, downTime=902633, deviceId=-1, source=0x101 }
2020-01-06 21:43:43.793 4923-4923/com.iris.idrs.smartcapture W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
2020-01-06 21:43:43.794 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 75 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:44.175 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:43.376 4923-4923/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) identical 7 lines
2020-01-06 21:43:43.376 4923-4923/com.iris.idrs.smartcapture W/ViewRootImpl[CConversionActivity]: Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x68, repeatCount=0, eventTime=902692, downTime=902633, deviceId=-1, source=0x101 }
2020-01-06 21:43:47.715 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:48.918 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:49.436 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346907648 ==== Initialization complete
2020-01-06 21:43:49.722 4923-4964/com.iris.idrs.smartcapture I/rs.smartcaptur: Background concurrent copying GC freed 2020(149KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 9MB/15MB, paused 1.459ms total 272.922ms
2020-01-06 21:43:49.772 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346907968 ==== Initialization complete
2020-01-06 21:43:49.802 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346900368 ==== Initialization complete
2020-01-06 21:43:49.888 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 41 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:50.151 4923-4923/com.iris.idrs.smartcapture E/CCaptureActivity: The camera encountered an error: 4
2020-01-06 21:43:50.198 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:50.266 4923-4964/com.iris.idrs.smartcapture I/rs.smartcaptur: NativeAlloc concurrent copying GC freed 5180(277KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 23MB/29MB, paused 1.626ms total 100.079ms
2020-01-06 21:43:52.168 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 45 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:52.961 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:53.167 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:54.084 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:44:04.197 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 57 frames! The application may be doing too much work on its main thread.
2020-01-06 21:44:08.168 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:44:08.172 4923-4961/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) FinalizerDaemon identical 7 lines
2020-01-06 21:44:08.172 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:44:51.860 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=973ms; Flags=1, IntendedVsync=971138216354, Vsync=971588216336, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=971604458900, AnimationStart=971604599700, PerformTraversalsStart=971605101500, DrawStart=972056683900, SyncQueued=972057201200, SyncStart=972057276400, IssueDrawCommandsStart=972057444900, SwapBuffers=972059625400, FrameCompleted=972111965000, DequeueBufferDuration=621000, QueueBufferDuration=1859000,
2020-01-06 21:44:51.861 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread.
2020-01-06 21:44:51.951 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:44:51.998 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:44:52.081 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=732ms; Flags=0, IntendedVsync=971597490482, Vsync=972097490462, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=972112842700, AnimationStart=972112945800, PerformTraversalsStart=972114580600, DrawStart=972248683500, SyncQueued=972248764000, SyncStart=972251096700, IssueDrawCommandsStart=972253391700, SwapBuffers=972254863000, FrameCompleted=972332311000, DequeueBufferDuration=136000, QueueBufferDuration=17695000,
2020-01-06 21:44:52.081 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
I/CCaptureActivity: Capture size selected: 960 x 1280
2020-01-06 21:44:55.241 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346895328 ==== Initialization complete
2020-01-06 21:44:55.286 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346899568 ==== Initialization complete
2020-01-06 21:44:55.320 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346553712 ==== Initialization complete
2020-01-06 21:44:55.846 4923-4964/com.iris.idrs.smartcapture I/rs.smartcaptur: NativeAlloc concurrent copying GC freed 66(54KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 23MB/29MB, paused 1.424ms total 473.768ms
2020-01-06 21:44:55.938 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
I have also noticed sometimes it work only first time and then second time it shows white screen.
Here is the capture activity code
public class CCaptureActivity extends AppCompatActivity
{
/**
* Activity creation handler.
* #param argSavedInstanceState Instance saved during previous session (unused).
*/
#Override
protected void onCreate ( final Bundle argSavedInstanceState )
{
super.onCreate ( argSavedInstanceState );
// Fetch the UI elements which will be updated programatically during activity runtime.
setContentView ( R.layout.activity_capture );
m_objDocumentAreaView = (CDocumentAreaView) findViewById ( R.id.corners_view );
m_objCameraView = (CCameraView) findViewById ( R.id.camera_view );
// Select the camera to use and initialize it as well as its preview and the needed handlers.
m_objPreviewImageListener = new CCaptureAnalysisRunner ();
setupCameraViewListener ();
setupCameraStatusCallback ();
m_objPreviewThread = new HandlerThread ( "PreviewUpdate" );
m_objCameraManager = (CameraManager) getSystemService ( Context.CAMERA_SERVICE );
getCamera ();
m_objHardwareStatus.onCreate ( this );
}
#Override
protected void onResume ()
{
super.onResume ();
m_objHardwareStatus.onResume ();
m_objIdrsCapture.onResume ( this );
openCamera ();
}
#Override
protected void onPause ()
{
m_objIdrsCapture.onPause ();
m_objHardwareStatus.onPause ();
closeCamera ();
super.onPause ();
}
private class CCaptureAnalysisRunner implements ImageReader.OnImageAvailableListener
{
public void onImageAvailable ( final ImageReader argImageReader )
{
final Image objCapturedImage = argImageReader.acquireLatestImage ();
// The image may be null sometimes, so skip processing in such case
if ( null != objCapturedImage )
{
final boolean bDocumentExposureOk = m_objHardwareStatus.isExposureOk ();
final boolean bCameraFocusSet = ( bDocumentExposureOk && m_objHardwareStatus.isFocusSet ());
final boolean bDeviceStable = ( bCameraFocusSet && m_objHardwareStatus.isDeviceStable ());
final CIdrsCapture.CWorker objWorker = (( bDeviceStable || m_bForceCapture ) ? m_objIdrsCapture.tryLock () : null );
if ( objWorker != null )
{
Log.i ( "CCaptureActivity", "An image is available and will be processed" );
objWorker.setCurrentCapture ( objCapturedImage );
objCapturedImage.close ();
AsyncTask.execute ( new Runnable ()
{
#Override
public void run ()
{
onImageAnalysisCompleted ( objWorker, objWorker.detectDocumentCorners ());
}
});
}
else
{
objCapturedImage.close ();
}
// In any case, the indicators must be updated
runOnUiThread ( new Runnable ()
{
#Override
public void run ()
{
if ( m_objDocumentAreaView.reduceIntensity ())
{
m_objCornersFlag.setChecked ( false );
m_objAreaFlag.setChecked ( false );
}
m_objExposureFlag.setChecked ( bDocumentExposureOk );
m_objFocusFlag.setChecked ( bCameraFocusSet );
m_objStabilityFlag.setChecked ( bDeviceStable );
m_objDocumentAreaView.invalidate ();
m_objExposureFlag.invalidate ();
m_objFocusFlag.invalidate ();
m_objStabilityFlag.invalidate ();
}
});
}
}
private void onImageAnalysisCompleted (final CIdrsCapture.CWorker argWorker, final CIdrsCapture.DocumentCorners argDocumentCorners)
{
if ( ! m_objIdrsCapture.isCaptureSelected ())
{
runOnUiThread(new Runnable()
{
#Override
public void run()
{
m_objCornersFlag.setChecked(argDocumentCorners.bCornersFound);
m_objAreaFlag.setChecked(argDocumentCorners.bTargetAreaOk);
if (argDocumentCorners.bCornersFound)
{
m_objDocumentAreaView.setDetectedCorners(argDocumentCorners.xiCorners, argDocumentCorners.bTargetAreaOk);
}
m_objDocumentAreaView.invalidate();
m_objCornersFlag.invalidate();
m_objAreaFlag.invalidate();
}
});
try
{
if (( argDocumentCorners.bCornersFound && argDocumentCorners.bTargetAreaOk ) || m_bForceCapture )
{
final int iCaptureQuality = m_bForceCapture ? 100 : argWorker.evaluateQuality ();
boolean bCurrentCaptureSelected = false;
boolean bCurrentCaptureForced = false;
synchronized ( m_objCaptureSelectionLock )
{
if (iCaptureQuality >= CAPTURE_QUALITY_THRESHOLD && ! m_objIdrsCapture.isCaptureSelected ())
{
argWorker.selectCapture();
bCurrentCaptureSelected = true;
if ( m_bForceCapture )
{
bCurrentCaptureForced = true;
m_bForceCapture = false;
}
}
}
// Update the controls only if no capture are currently selected or if this capture is the one selected
final boolean bCurrentCaptureSelectedFinal = bCurrentCaptureSelected;
final boolean bCurrentCaptureForcedFinal = bCurrentCaptureForced;
if ( bCurrentCaptureSelected || ! m_objIdrsCapture.isCaptureSelected ())
{
runOnUiThread(new Runnable()
{
#Override
public void run()
{
if ( ! bCurrentCaptureForcedFinal )
{
m_objImageQualityBar.setProgress(iCaptureQuality);
}
if ( bCurrentCaptureSelectedFinal )
{
m_objDocumentAreaView.setCaptureValidated();
}
m_objImageQualityBar.invalidate();
m_objCameraView.invalidate();
}
});
if ( bCurrentCaptureSelected )
{
final String strSelectedImagePath = CPathProvider.getInternalPathSelectedImage ();
argWorker.saveSelectedCapture ( strSelectedImagePath );
final Intent objCaptureCorrectionIntent = new Intent ( CCaptureActivity.this, CAdjustmentActivity.class );
objCaptureCorrectionIntent.putExtra ( "EXTRA_CAPTURED_IMAGE", strSelectedImagePath );
if ( argDocumentCorners.bCornersFound )
{
objCaptureCorrectionIntent.putExtra ( "EXTRA_DETECTED_CORNERS", argDocumentCorners.xiCorners );
}
CCaptureActivity.this.startActivity ( objCaptureCorrectionIntent );
}
}
}
}
finally
{
// Unlock the worker before exiting
argWorker.unlock ();
}
}
}
}
/**
* Setup the listener class that links the view to the camera.
*/
private void setupCameraViewListener ()
{
m_objCameraView.setSurfaceTextureListener ( new TextureView.SurfaceTextureListener ()
{
/**
* Surface texture available handler.
* #param argSurfaceTexture The surface texture (unused)
* #param iWidth Surface texture width (unused)
* #param iHeight Surface texture height (unused)
*/
#Override
public void onSurfaceTextureAvailable ( final SurfaceTexture argSurfaceTexture, final int iWidth, final int iHeight )
{
// No need to use the provided parameters - simply open the camera.
openCamera ();
}
#Override
public void onSurfaceTextureSizeChanged ( final SurfaceTexture argSurfaceTexture, final int iWidth, final int iHeight )
{
}
#Override
public boolean onSurfaceTextureDestroyed ( final SurfaceTexture argSurfaceTexture )
{
return true;
}
#Override
public void onSurfaceTextureUpdated ( final SurfaceTexture argSurfaceTexture )
{
}
});
}
/**
* Setup the camera status callback listener.
*/
private void setupCameraStatusCallback ()
{
m_objCameraStateCallback = new CameraDevice.StateCallback ()
{
/**
* Camera open handler.
* #param argCameraDevice The camera opened.
*/
#Override
public void onOpened ( final CameraDevice argCameraDevice )
{
m_objCameraDevice = argCameraDevice;
startCamera ();
}
#Override
public void onDisconnected ( final CameraDevice argCameraDevice )
{
}
#Override
public void onError ( final CameraDevice argCameraDevice, final int iError )
{
if ( m_objCameraDevice != null && m_objCameraDevice.getId ().equals ( argCameraDevice.getId ()))
{
Log.e ( "CCaptureActivity", "The camera encountered an error: " + iError );
}
}
};
}
private void getCamera ()
{
try
{
// Parse all available cameras and select the first rear-facing found.
m_strCameraId = null;
CameraCharacteristics objCameraCharacteristics = null;
final String[] xstrCameraIds = m_objCameraManager.getCameraIdList ();
for ( final String strCurrentCameraId : xstrCameraIds )
{
objCameraCharacteristics = m_objCameraManager.getCameraCharacteristics ( strCurrentCameraId );
if ( objCameraCharacteristics.get ( CameraCharacteristics.LENS_FACING ) == CameraCharacteristics.LENS_FACING_BACK )
{
m_strCameraId = strCurrentCameraId;
break;
}
}
if (m_strCameraId == null)
{
Log.e("CCaptureActivity", "Could not find device back camera");
}
final StreamConfigurationMap objStreamConfigurationMap = objCameraCharacteristics.get ( CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP );
m_iCameraOrientation = objCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Finally, retrieve the capture and preview sizes.
m_objCaptureSize = selectCaptureSize ( objStreamConfigurationMap.getOutputSizes ( ImageFormat.YUV_420_888 ), m_iCameraOrientation );
m_objPreviewSize = selectPreviewSize ( objStreamConfigurationMap.getOutputSizes ( SurfaceTexture.class ), m_objCaptureSize );
Log.i ("CCaptureActivity", "Capture size selected: " + m_objCaptureSize.getHeight () + " x " + m_objCaptureSize.getWidth ());
m_objIdrsCapture.setCharacteristics ( m_objCaptureSize, m_iCameraOrientation );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred while retrieving the device camera", argException );
}
}
private void openCamera ()
{
try
{
// Start or restart the preview handler if needed
if ( ! m_objPreviewThread.isAlive() || m_objPreviewThread.isInterrupted ())
{
m_objPreviewThread.start();
}
m_objPreviewThreadHandler = new Handler ( m_objPreviewThread.getLooper ());
m_objImageReader = ImageReader.newInstance ( m_objCaptureSize.getWidth (), m_objCaptureSize.getHeight (), ImageFormat.YUV_420_888, 2 );
m_objImageReader.setOnImageAvailableListener ( m_objPreviewImageListener, m_objPreviewThreadHandler );
m_objDocumentAreaView.setCaptureSize ( m_objCaptureSize, m_iCameraOrientation );
m_objCameraView.setCaptureSize ( m_objCaptureSize );
m_objCameraManager.openCamera ( m_strCameraId, m_objCameraStateCallback,null );
m_bCameraOpen = true;
}
catch ( final SecurityException argSecurityException )
{
Log.e ( "CCaptureActivity", "A security exception occurred while opening the device camera", argSecurityException );
}
catch (final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred while opening the device camera", argException );
}
}
private void startCamera ()
{
if ( m_objCameraDevice == null || ! m_objCameraView.isAvailable () || m_objPreviewSize == null )
{
return;
}
final SurfaceTexture argSurfaceTexture = m_objCameraView.getSurfaceTexture ();
if ( argSurfaceTexture == null )
{
return;
}
argSurfaceTexture.setDefaultBufferSize ( m_objPreviewSize.getWidth (), m_objPreviewSize.getHeight ());
final Surface argSurface = new Surface ( argSurfaceTexture );
try
{
m_objCaptureRequestBuilder = m_objCameraDevice.createCaptureRequest ( CameraDevice.TEMPLATE_PREVIEW );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred when creating the capture request", argException );
}
m_objCaptureRequestBuilder.addTarget ( argSurface );
m_objCaptureRequestBuilder.addTarget ( m_objImageReader.getSurface ());
try
{
m_objCameraDevice.createCaptureSession ( Arrays.asList ( argSurface, m_objImageReader.getSurface ()),
new CameraCaptureSession.StateCallback ()
{
#Override
public void onConfigured ( final CameraCaptureSession argCameraCaptureSession )
{
m_objCameraCaptureSession = argCameraCaptureSession;
onCaptureSessionConfigured ();
}
#Override
public void onConfigureFailed ( final CameraCaptureSession argCameraCaptureSession )
{
Log.e ("CCaptureActivity", "The camera capture session could not be successfully created." );
}
},
null );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred when creating the capture session", argException );
}
}
/**
* Callback that will start capture session once it is configured.
*/
private void onCaptureSessionConfigured ()
{
if ( m_objCameraDevice == null )
{
return;
}
m_objCaptureRequestBuilder.set ( CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO );
try
{
m_objCameraCaptureSession.setRepeatingRequest ( m_objCaptureRequestBuilder.build (),
m_objHardwareStatus,
m_objPreviewThreadHandler );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occured while starting capture session", argException );
}
}
private void closeCamera ()
{
if ( m_bCameraOpen )
{
m_objCameraDevice.close ();
m_bCameraOpen = false;
}
if( m_objCameraCaptureSession != null )
{
m_objCameraCaptureSession.close();
}
}
private Size selectCaptureSize ( final Size [] xargSizes, final int iCameraOrientation )
{
// Retrieve the screen dimensions to know its aspect ratio
final DisplayMetrics objDisplayMetrics = new DisplayMetrics ();
getWindowManager().getDefaultDisplay ().getMetrics ( objDisplayMetrics );
final float fScreenRatio = (float) objDisplayMetrics.widthPixels / objDisplayMetrics.heightPixels;
Size objMaxSizeSameRatio = null;
Size objMaxSizeAnyRatio = null;
// Now iterates on the list to find the largest (in area) below the accepted limit
for (final Size objCurrent : xargSizes )
{
final int iAreaSize = objCurrent.getHeight () * objCurrent.getWidth ();
final float fSizeRatio;
if ( iCameraOrientation == 0 || iCameraOrientation == 180)
{
fSizeRatio = (float) objCurrent.getWidth () / objCurrent.getHeight ();
}
else
{
fSizeRatio = (float) objCurrent.getHeight () / objCurrent.getWidth ();
}
if ( iAreaSize < CAPTURE_SIZE_MAX_PIXELS )
{
// Search with same ratio
if ( fSizeRatio == fScreenRatio &&
( objMaxSizeSameRatio == null || ( objMaxSizeSameRatio.getWidth () * objMaxSizeSameRatio.getHeight () < iAreaSize )))
{
objMaxSizeSameRatio = objCurrent;
}
// Search as well without taking the ratio into account
if ( objMaxSizeAnyRatio == null || ( objMaxSizeAnyRatio.getWidth () * objMaxSizeAnyRatio.getHeight () < iAreaSize ))
{
objMaxSizeAnyRatio = objCurrent;
}
}
}
return objMaxSizeSameRatio != null ? objMaxSizeSameRatio : objMaxSizeAnyRatio;
}
My app gets data from a PHP file. 3 normal textdata and 5 image urls. The app displays them in a recyclerview with cardviews.
My problem is, that the app crashes when getting empty image urls.
But with empty textdata the app works without problems.
Like:
textdata with content + image urls with content = works
Empty textdata + empty image urls = App crashes
Empty textdata + image urls with content = works
textdata with content + empty image urls = App crashes
This is the getting and sending (to RecyclerviewAdapter) Code:
public void JSON_DATA_WEB_CALL (String url){
jsonArrayRequest = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
JSON_PARSE_DATA_AFTER_WEBCALL(response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest);
}
public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {
for (int i = 0; i < array.length(); i++) {
GetDataAdapter GetDataAdapter2 = new GetDataAdapter();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetDataAdapter2.setImageUrl(json.getString(Image_URL_JSON));
GetDataAdapter2.setImageUrl2(json.getString(Image_URL_JSON2));
GetDataAdapter2.setImageUrl3(json.getString(Image_URL_JSON3));
GetDataAdapter2.setImageUrl4(json.getString(Image_URL_JSON4));
GetDataAdapter2.setImageUrl5(json.getString(Image_URL_JSON5));
GetDataAdapter2.setPhone_number(json.getString(SOMETEXT));
GetDataAdapter2.setName(json.getString(SOMETEXT2));
GetDataAdapter2.setSubject2(json.getString(SOMETEXT3));
} catch (JSONException e) {
e.printStackTrace();
}
GetDataAdapter1.add(GetDataAdapter2);
}
recyclerViewadapter = new RecyclerViewAdapter(solutionTemplate.this, GetDataAdapter1, exerciseAdapter);
recyclerView.setAdapter(recyclerViewadapter);
}
The mainproblem is:
json = array.getJSONObject(i);
GetDataAdapter2.setImageUrl(json.getString(Image_URL_JSON));
GetDataAdapter2.setImageUrl2(json.getString(Image_URL_JSON2));
GetDataAdapter2.setImageUrl3(json.getString(Image_URL_JSON3));
GetDataAdapter2.setImageUrl4(json.getString(Image_URL_JSON4));
GetDataAdapter2.setImageUrl5(json.getString(Image_URL_JSON5));
GetDataAdapter2.setPhone_number(json.getString(SOMETEXT));
GetDataAdapter2.setName(json.getString(SOMETEXT2));
GetDataAdapter2.setSubject2(json.getString(SOMETEXT3));
Working:
json = array.getJSONObject(i);
GetDataAdapter2.setImageUrl(json.getString(Image_URL_JSON));
GetDataAdapter2.setImageUrl2(json.getString(Image_URL_JSON2));
GetDataAdapter2.setImageUrl3(json.getString(Image_URL_JSON3));
GetDataAdapter2.setImageUrl4(json.getString(Image_URL_JSON4));
GetDataAdapter2.setImageUrl5(json.getString(Image_URL_JSON5));
Not working:
GetDataAdapter2.setPhone_number(json.getString(SOMETEXT));
GetDataAdapter2.setName(json.getString(SOMETEXT2));
GetDataAdapter2.setSubject2(json.getString(SOMETEXT3));
Getting image urls with content is necassary!
But it should work without it!
This is the GetDataAdapter:
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number1) {
this.phone_number = phone_number1;
}
public String getSubject2() {
return subject2;
}
public void setSubject2(String subject2) {
this.subject2 = subject2;
}
public String getImageUrl() {
return ImageURL;
}
public void setImageUrl(String imageServerUrl) {
this.ImageURL = imageServerUrl;
}
public String getImageUrl2() {
return ImageURL2;
}
public void setImageUrl2(String imageServerUrl2) {
this.ImageURL2 = imageServerUrl2;
}
public String getImageUrl3() {
return ImageURL3;
}
public void setImageUrl3(String imageServerUrl3) {
this.ImageURL3 = imageServerUrl3;
}
public String getImageUrl4() {
return ImageURL4;
}
public void setImageUrl4(String imageServerUrl4) {
this.ImageURL4 = imageServerUrl4;
}
public String getImageUrl5() {
return ImageURL5;
}
public void setImageUrl5(String imageServerUrl5) {
this.ImageURL5 = imageServerUrl5;
}
RecyclerViewAdapter:
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolder) {
final GetDataAdapter current = getItem(position - 1);
final ViewHolder holder1 = (ViewHolder) holder;
final ImageLoader imageLoader = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader2 = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader3 = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader4 = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader5 = ImageAdapter.getInstance(context).getImageLoader();
imageLoader.get(current.getImageUrl(),
ImageLoader.getImageListener(
holder1.imageView1,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader2.get(current.getImageUrl2(),
ImageLoader.getImageListener(
holder1.imageView2,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader3.get(current.getImageUrl3(),
ImageLoader.getImageListener(
holder1.imageView3,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader4.get(current.getImageUrl4(),
ImageLoader.getImageListener(
holder1.imageView4,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader5.get(current.getImageUrl5(),
ImageLoader.getImageListener(
holder1.imageView5,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
holder1.imageView1.setImageUrl(current.getImageUrl(), imageLoader);
holder1.imageView2.setImageUrl(current.getImageUrl2(), imageLoader2);
holder1.imageView3.setImageUrl(current.getImageUrl3(), imageLoader3);
holder1.imageView4.setImageUrl(current.getImageUrl4(), imageLoader4);
holder1.imageView5.setImageUrl(current.getImageUrl5(), imageLoader5);
holder1.NameTextView.setText(current.getName());
holder1.PhoneNumberTextView.setText(current.getPhone_number());
holder1.SubjectTextView.setText(current.getSubject2());
ImageAdapter:
public class ImageAdapter {
public static ImageAdapter imageAdapter;
public Network networkOBJ ;
public RequestQueue requestQueue1;
public ImageLoader Imageloader1;
public Cache cache1 ;
public static Context context1;
LruCache<String, Bitmap> LRUCACHE = new LruCache<String, Bitmap>(30);
private ImageAdapter(Context context) {
this.context1 = context;
this.requestQueue1 = RequestQueueFunction();
Imageloader1 = new ImageLoader(requestQueue1, new ImageLoader.ImageCache() {
#Override
public Bitmap getBitmap(String URL) {
return LRUCACHE.get(URL);
}
#Override
public void putBitmap(String url, Bitmap bitmap) {
LRUCACHE.put(url, bitmap);
}
});
}
public ImageLoader getImageLoader() {
return Imageloader1;
}
public static ImageAdapter getInstance(Context SynchronizedContext) {
if (imageAdapter == null) {
imageAdapter = new ImageAdapter(SynchronizedContext);
}
return imageAdapter;
}
public RequestQueue RequestQueueFunction() {
if (requestQueue1 == null) {
cache1 = new DiskBasedCache(context1.getCacheDir());
networkOBJ = new BasicNetwork(new HurlStack());
requestQueue1 = new RequestQueue(cache1, networkOBJ);
requestQueue1.start();
}
return requestQueue1;
}
}
PHP:
<?php
$conn = mysqli_connect('localhost', 'root', '','webapp');
$id = $_GET['id'];
$sql = "SELECT * FROM answers WHERE id='$id' ORDER BY id DESC";
$res = mysqli_query($conn,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,array(
'url2'=>$row['images'],
'url3'=>$row['images2'],
'url4'=>$row['images3'],
'url5'=>$row['images4'],
'url6'=>$row['images5'],
'subject'=>$row['subject'],
'phone'=>$row['phone'],
'name'=>$row['name']));
}
echo json_encode(array_values($result));
mysqli_close($conn);
?>
If PHP sends url2, url3, url4... without content the app chrashes, but phone, name, subject with empty values works without problems.
I think Android has a Problem with converting empty imageurls and with displaying it.
EDIT:
A lot of users said that I have to add the Logcat:
07-16 13:12:10.713 1578-1990/system_process W/ActivityManager: Force finishing activity com.example.jakob.webapplicationsave/.solutionTemplate
07-16 13:12:10.822 1578-1990/system_process W/ActivityManager: Force finishing activity com.example.jakob.webapplicationsave/.Main2Activity
07-16 13:12:10.946 1578-2630/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
07-16 13:12:10.947 1578-2630/system_process D/EGL_emulation: eglCreateContext: 0x9c2be040: maj 2 min 0 rcv 2
07-16 13:12:10.953 1578-2630/system_process D/EGL_emulation: eglMakeCurrent: 0x9c2be040: ver 2 0 (tinfo 0x9efbd6e0)
07-16 13:12:10.962 1578-2630/system_process D/EGL_emulation: eglMakeCurrent: 0x9c2be040: ver 2 0 (tinfo 0x9efbd6e0)
07-16 13:12:11.323 1578-1592/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{e46f507 u0 com.example.jakob.webapplicationsave/.solutionTemplate t497 f}
07-16 13:12:11.372 1930-2076/com.android.launcher3 I/OpenGLRenderer: Initialized EGL, version 1.4
07-16 13:12:11.374 1930-2076/com.android.launcher3 D/EGL_emulation: eglCreateContext: 0xae414660: maj 2 min 0 rcv 2
07-16 13:12:11.385 1930-2076/com.android.launcher3 D/EGL_emulation: eglMakeCurrent: 0xae414660: ver 2 0 (tinfo 0xae412440)
07-16 13:12:11.423 1930-2076/com.android.launcher3 D/EGL_emulation: eglMakeCurrent: 0xae414660: ver 2 0 (tinfo 0xae412440)
07-16 13:12:13.537 1270-1616/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 38006369 , only wrote 37870012
07-16 13:12:14.795 13519-13519/com.example.jakob.webapplicationsave I/Process: Sending signal. PID: 13519 SIG: 9
07-16 13:12:14.814 1578-2630/system_process D/EGL_emulation: eglMakeCurrent: 0x9c2be040: ver 2 0 (tinfo 0x9efbd6e0)
07-16 13:12:14.815 1578-2630/system_process E/Surface: getSlotFromBufferLocked: unknown buffer: 0x9b6834a0
07-16 13:12:14.830 1578-2182/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 104)
07-16 13:12:14.830 1578-2182/system_process W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 13519 uid 10062
07-16 13:12:14.833 1578-2182/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 104)
07-16 13:12:14.847 1578-1713/system_process D/GraphicsStats: Buffer count: 5
07-16 13:12:14.847 1578-1625/system_process W/InputDispatcher: channel '7af27b1 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
07-16 13:12:14.847 1578-2182/system_process I/WindowState: WIN DEATH: Window{7af27b1 u0 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity}
07-16 13:12:14.847 1578-1625/system_process E/InputDispatcher: channel '7af27b1 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity (server)' ~ Channel is unrecoverably broken and will be disposed!
07-16 13:12:14.847 1578-1625/system_process W/InputDispatcher: channel 'cd3daa3 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate (server)' ~ Consumer closed input channel or an error occurred. events=0x9
07-16 13:12:14.847 1578-1625/system_process E/InputDispatcher: channel 'cd3daa3 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate (server)' ~ Channel is unrecoverably broken and will be disposed!
07-16 13:12:14.847 1578-2182/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '7af27b1 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity (server)'
07-16 13:12:14.848 1578-2179/system_process I/WindowState: WIN DEATH: Window{cd3daa3 u0 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate}
07-16 13:12:14.848 1578-2179/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel 'cd3daa3 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate (server)'
07-16 13:12:14.853 1259-1259/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
07-16 13:12:14.853 1578-1963/system_process I/ActivityManager: Process com.example.jakob.webapplicationsave (pid 13519) has died
07-16 13:12:15.026 1578-1597/system_process W/AppOps: Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0
07-16 13:12:17.958 1270-1616/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 38145850 , only wrote 38008822
07-16 13:13:00.065 1259-1351/? D/hwcomposer: hw_composer sent 312 syncs in 60s
07-16 13:14:00.056 1259-1351/? D/hwcomposer: hw_composer sent 5 syncs in 60s
Here's my snippets :
public class MainActivity extends AppCompatActivity {
private int seekForwardTime = 5000;
private int seekBackwardTime = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekForward.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick (View v) {
Toast.makeText(getApplicationContext(), "Seek Forward music", Toast.LENGTH_SHORT).show();
forwardSong(mediaPlayer);
}
});
}
public void forwardSong(MediaPlayer mediaPlayer) {
int currentPosition = mediaPlayer.getCurrentPosition();
String tag2 = "currentPosition";
Log.v(tag2, String.valueOf(mediaPlayer.getCurrentPosition()));
if (currentPosition + seekForwardTime <= mediaPlayer.getCurrentPosition()) {
mediaPlayer.seekTo(currentPosition + seekForwardTime);
} else {
String tag = "main activity";
Log.v(tag, "else state");
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
}
As per title, I want to separate Fast Forward (seek 5 second forward for each press) behavior from seekForward.OnClickListener to another method (forwardSong).
But, when I trigger seekForward, instead of seeking, it kills mediaPlayer. So I have to press 'play' button again and start from beginning of song.
Am I missed something? I'm happy to receive any solution and/or advice.
ps : please ignore the Log statement, I'm just do some test before.
Thanks!
Edit - 09/08/2017
As requested, here's the logcat
08-09 16:36:01.688 2707-2707/? I/art: Not late-enabling -Xcheck:jni (already on)
08-09 16:36:01.688 2707-2707/? W/art: Unexpected CPU variant for X86 using defaults: x86
08-09 16:36:01.781 2707-2707/? W/System: ClassLoader referenced unknown path: /data/app/com.example.android.musicplayer-2/lib/x86
08-09 16:36:01.791 2707-2707/? I/InstantRun: starting instant run server: is main process
08-09 16:36:01.856 2707-2707/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-09 16:36:02.094 2707-2707/com.example.android.musicplayer D/MediaPlayer: setSubtitleAnchor in MediaPlayer
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer I/OpenGLRenderer: Initialized EGL, version 1.4
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer D/OpenGLRenderer: Swap behavior 1
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer D/OpenGLRenderer: Swap behavior 0
08-09 16:36:02.219 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglCreateContext: 0xa1328e80: maj 2 min 0 rcv 2
08-09 16:36:02.264 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:36:02.333 2707-2707/com.example.android.musicplayer W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
08-09 16:36:02.343 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:47.717 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:47.747 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:48.672 2707-2707/com.example.android.musicplayer V/currentPosition: 707
08-09 16:58:48.673 2707-2707/com.example.android.musicplayer V/main activity: else state
08-09 16:58:49.669 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:50.684 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:51.667 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:53.631 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
I'm confused. Why it entering else statement?
Modify your forwardSong function the following way :
public void forwardSong(MediaPlayer mediaPlayer) {
int currentPosition = mediaPlayer.getCurrentPosition();
String tag2 = "currentPosition";
Log.v(tag2, String.valueOf(mediaPlayer.getCurrentPosition()));
if (currentPosition + seekForwardTime <= mediaPlayer.getDuration()) {
mediaPlayer.seekTo(currentPosition + seekForwardTime);
} else {
String tag = "main activity";
Log.v(tag, "else state");
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
The following condition is the problem, it will be always false and the mediaplayer will always seek to the end of your media file because of your else statement.
if (currentPosition + seekForwardTime <= mediaPlayer.getCurrentPosition())