我的应用程序未从数据库中获取数据。它显示一个空白的文本视图,并说在下面给出的logcat错误..请帮助我。我在工作的最后期限.....
2020-02-26 11:53:30.062 29392-29392 / com.example.d_specs I / TextToSpeech:已成功绑定到com.google.android.tts
2020-02-26 11:53:30.070 29392-29418 / com.example.d_specs D / ColorExSystemServiceHelper:checkColorExSystemService className = com.google.android.tts.service.GoogleTTSService
2020-02-26 11:53:30.075 29392-29392 / com.example.d_specs D / WindowManager:添加到mViews:DecorView @ fa8568c [SecondOneActivity],这= android.view.WindowManagerGlobal @ b0c7f51,pkg = com.example。 d_specs
2020-02-26 11:53:30.083 29392-29392 / com.example.d_specs I / TextToSpeech:已连接至ComponentInfo {com.google.android.tts / com.google.android.tts.service.GoogleTTSService}
2020-02-26 11:53:30.091 29392-29497 / com.example.d_specs I / TextToSpeech:设置与ComponentInfo {com.google.android.tts / com.google.android.tts.service.GoogleTTSService}的连接
2020-02-26 11:53:30.264 29392-29392 / com.example.d_specs I /编舞:跳过8帧!该应用程序可能在其主线程上做过多的工作。
2020-02-26 11:53:30.553 29392-29392 / com.example.d_specs D / SurfaceView:238649477 updateRequestedVisibility,mViewVisibility:true,mWindowVisibility:false,mWindowStopped:false由android.view.SurfaceView.onWindowVisibilityChanged:292 android.view .View.dispatchWindowVisibilityChanged:1580 android.view.ViewGroup.dispatchWindowVisibilityChanged:1580 android.view.ViewGroup.dispatchWindowVisibilityChanged:1580 android.view.ViewGroup.dispatchWindowVisibilityChanged:1580 android.view.ViewGroup.dispatchWindowVisibilityChanged:1580 1580 android.view.ViewGroup.dispatchWindowVisibilityChanged:1580
2020-02-26 11:53:30.553 29392-29392 / com.example.d_specs I / SurfaceView:238649477更改:creating = false format = false size = false visible = true visible = true left = false top = false
2020-02-26 11:53:30.553 29392-29392 / com.example.d_specs I / SurfaceView:238649477 Cur surface:Surface(name = null)/ @ 0xfeb1e8,visible = false
2020-02-26 11:53:30.555 29392-29392 / com.example.d_specs I / SurfaceView:238649477 visibleChanged:true-> SurfaceHolder.Callback.surfaceDestroyed
2020-02-26 11:53:30.557 29392-29392 / com.example.d_specs V / SurfaceView:布局:x = 0 y = 264 w = 1094 h = 1944,frame = Rect(0,0-1094,1944)
2020-02-26 11:53:30.559 29392-29480 / com.example.d_specs D / SurfaceView:135700481 windowPositionLost,frameNr = 0
2020-02-26 11:53:30.576 29392-29392 / com.example.d_specs D / SurfaceView:238649477 updateRequestedVisibility,mViewVisibility:true,mWindowVisibility:false,mWindowStopped:true由android.view.SurfaceView.windowStopped:264 android.view .ViewRootImpl.setWindowStopped:1722 android.view.WindowManagerGlobal.setStoppedState:685 android.app.Activity.performStop:8206 android.app.ActivityThread.callActivityOnStop:4899 android.app.ActivityThread.performStopActivityInner:4877 android.app.ActivityThread.performStopActivityInner:4877 android.app.ActivityThread.performStopActivityInner:4877 4959 android.app.servertransaction.StopActivityItem.execute:41
2020-02-26 11:54:08.979 29392-29392 / com.example.d_specs I /编舞:跳过2帧!该应用程序可能在其主线程上做过多的工作。
import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.core.view.GestureDetectorCompat;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import java.util.ArrayList;
import java.util.Locale;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
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.Query;
import com.google.firebase.database.ValueEventListener;
public class SecondOneActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
private static final String TAG = "SampleActivity";
private GestureDetectorCompat GestureDetect;
private TextToSpeech tts;
TextToSpeech txt;
//array declaration
ArrayList<String> array1;
ArrayList<String> array2;
//global variable
String glo;
String nameget;
String priceget;
TextView text;
FirebaseAuth firebaseAuth;
FirebaseUser firebaseUser;
DatabaseReference databasefetch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_one);
Bundle bundle = getIntent().getExtras(); //get the intent and data passed
//next check that bundle is not null
if (bundle != null) {
String scanResult = bundle.getString("SCAN_RESULT");
//try loging out the value
Log.i("value", scanResult);
glo = scanResult;
}
//typeCast
long l = Long.parseLong(glo);
//initialize arraylists
array1 = new ArrayList<String>();
array2 = new ArrayList<String>();
txt=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status!=TextToSpeech.ERROR)
{
txt.setLanguage(Locale.UK);
}
}
});
GestureDetect = new GestureDetectorCompat(this,this);
GestureDetect.setOnDoubleTapListener(this);
text = (TextView) findViewById(R.id.textView3);
//database initialize
firebaseAuth = FirebaseAuth.getInstance();
firebaseUser = firebaseAuth.getCurrentUser();
//database data fetching : from here onwards
//database query as "select * from save where id=l;
databasefetch = FirebaseDatabase.getInstance().getReference().child("DPOS");
Query query = databasefetch.orderByChild("id").equalTo(l);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Log.i("TAG", "sujith annan");
String name = snapshot.child("name").getValue().toString();
String details = snapshot.child("details").getValue().toString();
String price = snapshot.child("price").getValue().toString();
// nameget = name;
// priceget = price;
text = (TextView) findViewById(R.id.textView3);
//to print
text.setText("\nProduct Name : " + name + "\nDetails : " + details + "\nPrice : " + price);
//text to speech
String toSpeak = text.getText().toString();
Toast.makeText(getApplicationContext(),toSpeak,Toast.LENGTH_SHORT).show();
txt.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
throw databaseError.toException(); // never ignore errors
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
GestureDetect.onTouchEvent(event);
return super.onTouchEvent(event);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
//text to speech
String toSpeak = text.getText().toString();
Toast.makeText(getApplicationContext(),toSpeak,Toast.LENGTH_SHORT).show();
txt.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
Intent intent=new Intent(SecondOneActivity.this,SecondActivity.class);
startActivity(intent);
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Toast.makeText(this,"Item saved for billing",Toast.LENGTH_SHORT).show();
array1.add(nameget);
array2.add(priceget);
return false;
}
@Override
public void onBackPressed() {
Intent in =new Intent(this,BillingActivity.class);
in.putStringArrayListExtra("arr1",array1);
in.putStringArrayListExtra("arr2",array2);
startActivity(in);
super.onBackPressed();
}
}
最佳答案
您在主线程上执行了太多任务。因为android应用程序运行一个管理GUI的线程。
在您的代码中,您在主线程上调用了“ Firebase”。这就是为什么它会丢失一些要在屏幕上渲染的帧的原因。
如果错过许多帧,则有时您的“ UI”被冻结。避免
在主线程上调用Web服务或数据库操作。
为避免这种情况,您可以使用“ AsyncTask”或“服务”执行此任务。
谢谢