Привет! Я использовал встроенную панель навигации MainActivity и три фрагмента домашней галереи и слайд-шоу. В котором у меня есть две формы, одна находится в домашнем фрагменте, а другая - во фрагменте галереи. Домашняя форма работает нормально, а галерея - нет. Оба поля формы абсолютно одинаковы, кроме имени базы данных. Я отправлял данные обеих форм с помощью функции щелчка в MainActivity, но для формы галереи. произошел сбой, так как произошла ошибка кнопки «Отправить». Объект галереи имеет нулевое значение, поскольку его целевая страница является домашней, поэтому имеется только одна кнопка «Отправить». затем я создал еще одно действие, расширяющее основную активность в нем. Теперь проблема cra sh решена, но все равно не записывается в базу данных.
MainActivity работает нормально
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
Log.i(TAG, "onInstance");
// setContentView(R.layout.content_main);
//Checkbox of Guide
english = findViewById(R.id.eng_box);
interview = findViewById(R.id.inter_box);
internship = findViewById(R.id.intern_box);
resume = findViewById(R.id.cv_box);
promotion = findViewById(R.id.job_box);
confidence = findViewById(R.id.cnfdc_box);
exams = findViewById(R.id.exam_box);
//make button object
sendButton = findViewById(R.id.sendButton);
// Write a message to the database
final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
final String uid = firebaseUser.getUid();
final String uemail = firebaseUser.getEmail();
assert firebaseUser != null;
final String una = firebaseUser.getDisplayName(); //display the entire name
assert una != null;
final DatabaseReference myRef = database.getReference().child("Expert_expertise").child(uid);
final DatabaseReference TRef = database.getReference().child("Trainee_req").child(uid);
// FirebaseDatabase database = FirebaseDatabase.getInstance();
// DatabaseReference myRef = database.getReference("Expert Expertise");
// myRef.setValue("Hello, World!");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String value = dataSnapshot.child(uid).getValue(String.class);
Log.d(TAG, "Value is: " + value);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
// Failed to read value
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myRef.child("Name").setValue(una);
myRef.child("Email").setValue(uemail);
if(english.isChecked()) {
myRef.child("Spoken English").setValue("True");
}
else{
myRef.child("Spoken English").setValue("False");
}
if(interview.isChecked()) {
myRef.child("Interview Tips").setValue("True");
}
else{
myRef.child("Interview Tips").setValue("False");
}
if(internship.isChecked()) {
myRef.child("Internship Guide").setValue("True");
}
else{
myRef.child("Internship Guide").setValue("False");
}
if(resume.isChecked()) {
myRef.child("Resume Building").setValue("True");
}
else{
myRef.child("Resume Building").setValue("False");
}
if(promotion.isChecked()) {
myRef.child("Job Promotion").setValue("True");
}
else{
myRef.child("Job Promotion").setValue("False");
}
if(confidence.isChecked()) {
myRef.child("Confidence Development").setValue("True");
}
else{
myRef.child("Confidence Development").setValue("False");
}
if(exams.isChecked()) {
myRef.child("Competitive Exams").setValue("True");
}
else{
myRef.child("Competitive Exams").setValue("False");
}
Toast.makeText(getApplicationContext(),"Thank You! Your expertise is successfully saved",Toast.LENGTH_SHORT).show();
}
});
// System.out.print("Hello, Saurabh");
// Toast.makeText(getApplicationContext(),"Unable to submit",Toast.LENGTH_SHORT).show();
// Log.i(TAG, "Hello Saurabh");
}
GalleryForm
package com.example.pdshell;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.database.annotations.Nullable;
public class GalleryForm extends Dashboard {
private static final String TAG="Mymessage";
CheckBox t_english,t_interview,t_internship,t_resume,t_promotion,t_confidence,t_exams;
Button sendButton, t_button;
FirebaseDatabase database = FirebaseDatabase.getInstance();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.fragment_gallery);
//Checkbox of Trainee
t_english = findViewById(R.id.t_eng_box);
t_interview = findViewById(R.id.t_inter_box);
t_internship = findViewById(R.id.t_intern_box);
t_resume = findViewById(R.id.t_cv_box);
t_promotion = findViewById(R.id.t_job_box);
t_confidence = findViewById(R.id.t_cnfdc_box);
t_exams = findViewById(R.id.t_exam_box);
//make button object
t_button = findViewById(R.id.t_sendButton);
final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
final String uid = firebaseUser.getUid();
final String uemail = firebaseUser.getEmail();
assert firebaseUser != null;
final String una = firebaseUser.getDisplayName(); //display the entire name
assert una != null;
final DatabaseReference TRef = database.getReference().child("Trainee_req").child(uid);
TRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String value = dataSnapshot.child(uid).getValue(String.class);
Log.d(TAG, "Value is: " + value);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
// Failed to read value
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
System.out.print("Hello, Saurabh@");
Toast.makeText(getApplicationContext(),"Unable to submit!",Toast.LENGTH_SHORT).show();
Log.i(TAG, "Hello Saurabh#");
t_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TRef.child("Name").setValue(una);
TRef.child("Email").setValue(uemail);
if (t_english.isChecked()) {
TRef.child("Spoken English").setValue("True");
} else {
TRef.child("Spoken English").setValue("False");
}
System.out.print("Hello, Saurabh$");
Toast.makeText(getApplicationContext(),"Unable to submit%",Toast.LENGTH_SHORT).show();
Log.i(TAG, "Hello Saurabh^");
if (t_interview.isChecked()) {
TRef.child("Interview Tips").setValue("True");
} else {
TRef.child("Interview Tips").setValue("False");
}
if (t_internship.isChecked()) {
TRef.child("Internship Guide").setValue("True");
} else {
TRef.child("Internship Guide").setValue("False");
}
if (t_resume.isChecked()) {
TRef.child("Resume Building").setValue("True");
} else {
TRef.child("Resume Building").setValue("False");
}
if (t_promotion.isChecked()) {
TRef.child("Job Promotion").setValue("True");
} else {
TRef.child("Job Promotion").setValue("False");
}
if (t_confidence.isChecked()) {
TRef.child("Confidence Development").setValue("True");
} else {
TRef.child("Confidence Development").setValue("False");
}
if (t_exams.isChecked()) {
TRef.child("Competitive Exams").setValue("True");
} else {
TRef.child("Competitive Exams").setValue("False");
}
Toast.makeText(getApplicationContext(), "Thank you! Your requirements is successfully saved", Toast.LENGTH_SHORT).show();
}
});
}
}
logcat
020-04-25 20:38:00.748 21631-18049/? E/SQLiteDatabase: Error inserting period=86400000 target_class=com.firebase.jobdispatcher.GooglePlayReceiver required_network_type=0 runtime=1587827280741 required_idleness_state=0 extras={"com.firebase.jobdispatcher.tag":{"retry_all":4},"com.firebase.jobdispatcher.trigger_type":{"1":0},"com.firebase.jobdispatcher.replace_current":{"true":3},"com.firebase.jobdispatcher.persistent":{"2":0},"com.firebase.jobdispatcher.maximum_backoff_seconds":{"3600":0},"com.firebase.jobdispatcher.initial_backoff_seconds":{"30":0},"com.firebase.jobdispatcher.retry_policy":{"1":0},"com.firebase.jobdispatcher.window_end":{"86400":0},"com.firebase.jobdispatcher.service":{"com.phonepe.phonepecore.gcm.FailedRequestReattemptHelper":4},"com.firebase.jobdispatcher.recurring":{"false":3},"com.firebase.jobdispatcher.constraints":{"2":0},"com.firebase.jobdispatcher.window_start":{"1":0}} source=8 service_kind=0 target_package=com.phonepe.app source_version=1 last_runtime=0 user_id=0 job_id=-1 requires_charging=0 tag=retry_all flex_time=1000 task_type=0 retry_strategy={"maximum_backoff_seconds":{"3600":0},"initial_backoff_seconds":{"30":0},"retry_policy":{"0":0}}
android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: pending_ops.tag, pending_ops.target_class, pending_ops.target_package, pending_ops.user_id (code 2067 SQLITE_CONSTRAINT_UNIQUE)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:831)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1564)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1433)
at aqch.a(:com.google.android.gms@201216030@20.12.16 (100408-306753009):78)
at aqbw.a(:com.google.android.gms@201216030@20.12.16 (100408-306753009):167)
at aqbw.a(:com.google.android.gms@201216030@20.12.16 (100408-306753009):21)
at aqbw.a(:com.google.android.gms@201216030@20.12.16 (100408-306753009):161)
at apyg.run(:com.google.android.gms@201216030@20.12.16 (100408-306753009):8)
at thp.b(:com.google.android.gms@201216030@20.12.16 (100408-306753009):12)
at thp.run(:com.google.android.gms@201216030@20.12.16 (100408-306753009):7)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at tno.run(:com.google.android.gms@201216030@20.12.16 (100408-306753009):0)
at java.lang.Thread.run(Thread.java:764)
2020-04-25 20:38:01.674 2456-2456/? I/NetLowlatency: setDataPhoneId: 1
2020-04-25 20:38:01.686 2456-2456/? I/NetLowlatency: setDataPhoneId: 1
2020-04-25 20:38:01.686 2456-2456/? I/NetLowlatency: is automode : true
2020-04-25 20:38:01.686 2456-2456/? I/NetLowlatency: get the current uplink latency level is 1
2020-04-25 20:38:01.850 13692-13692/? I/hostapd: wlan0: STA 4c:18:9a:b9:4f:2a IEEE 802.11: associated
2020-04-25 20:38:01.850 844-844/? I/wificond: New station 4c:18:9a:b9:4f:2a associated with hotspot
2020-04-25 20:38:01.850 13692-13692/? I/hostapd: wlan0: STA 4c:18:9a:b9:4f:2a IEEE 802.11: associated
2020-04-25 20:38:01.850 13692-13692/? E/hostapd: New STA hapd->num_sta=1 hapd->conf->max_num_sta=255 net.wifi.vivosoftap.maxsta=1
2020-04-25 20:38:01.850 13692-13692/? E/hostapd: no more room for new STAs (1/255)