Guest User

Untitled

a guest
Nov 15th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. public class buscador extends AppCompatActivity {
  2.  
  3. ListView lv;
  4. private DatabaseReference myRef,ref,ref2;
  5. private FirebaseAuth mAuth;
  6. private FirebaseAuth.AuthStateListener mAuthListner;
  7. private String id;
  8. private FirebaseDatabase mFirebaseDatabase;
  9. private static final String TAG = "buscador";
  10. int num=1;
  11. private ArrayList<String> array2;
  12.  
  13. @Override
  14. protected void onCreate(@Nullable Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.buscador);
  17.  
  18. lv=(ListView)findViewById(R.id.cat1);
  19. EditText search = (EditText)findViewById(R.id.searchfind);
  20. mAuth=FirebaseAuth.getInstance();
  21. FirebaseUser user=mAuth.getCurrentUser();
  22. id=ref.getKey();
  23.  
  24. setupFirebaseAuth();
  25.  
  26.  
  27. ref=FirebaseDatabase.getInstance().getReference("Products");
  28. ref.addValueEventListener(new ValueEventListener() {
  29. @Override
  30. public void onDataChange(DataSnapshot dataSnapshot) {
  31. showData(dataSnapshot);
  32. }
  33.  
  34. @Override
  35. public void onCancelled(DatabaseError databaseError) {
  36.  
  37. }
  38. });
  39. }
  40. public void showData(DataSnapshot dataSnapshot){
  41. for (DataSnapshot ds : dataSnapshot.getChildren()) {
  42. Producto info = new Producto();
  43. info.setName(ds.child(id).getValue(Producto.class).getName());
  44.  
  45. Log.d(TAG, "showData:name:" + info.getName());
  46. ArrayList<String> array=new ArrayList<>();
  47. array.add(info.getName());
  48. ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,array);
  49. lv.setAdapter(adapter);}
  50. }
  51.  
  52. public class Producto {
  53. private String image;
  54. private String name;
  55. private float price;
  56. private String descripcion;
  57. private String catalogo;
  58. private String id;
  59.  
  60. public Producto(String image, String name, float price, String descripcion, String catalogo, String id) {
  61. this.image = image;
  62. this.name = name;
  63. this.price = price;
  64. this.descripcion = descripcion;
  65. this.catalogo = catalogo;
  66. this.id = id;
  67. }
  68.  
  69. public Producto() {
  70. }
  71.  
  72. public String getImage() {
  73. return image;
  74. }
  75.  
  76. public void setImage(String image) {
  77. this.image = image;
  78. }
  79.  
  80. public String getName() {
  81. return name;
  82. }
  83.  
  84. public void setName(String name) {
  85. this.name = name;
  86. }
  87.  
  88. public float getPrice() {
  89. return price;
  90. }
  91.  
  92. public void setPrice(float price) {
  93. this.price = price;
  94. }
  95.  
  96. public String getDescripcion() {
  97. return descripcion;
  98. }
  99.  
  100. public void setDescripcion(String descripcion) {
  101. this.descripcion = descripcion;
  102. }
  103.  
  104. public String getCatalogo() {
  105. return catalogo;
  106. }
  107.  
  108. public void setCatalogo(String catalogo) {
  109. this.catalogo = catalogo;
  110. }
  111.  
  112. public String getId() {
  113. return id;
  114. }
  115.  
  116. public void setId(String id) {
  117. this.id = id;
  118. }
  119. }
  120.  
  121. Process: com.example.roge.navapp, PID: 32020
  122. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.roge.navapp/com.example.roge.navapp.buscador}: java.lang.NullPointerException
  123. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
  124. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
  125. at android.app.ActivityThread.access$800(ActivityThread.java:166)
  126. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
  127. at android.os.Handler.dispatchMessage(Handler.java:102)
  128. at android.os.Looper.loop(Looper.java:136)
  129. at android.app.ActivityThread.main(ActivityThread.java:5590)
  130. at java.lang.reflect.Method.invokeNative(Native Method)
  131. at java.lang.reflect.Method.invoke(Method.java:515)
  132. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
  133. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
  134. at dalvik.system.NativeStart.main(Native Method)
  135. Caused by: java.lang.NullPointerException
  136. at com.example.roge.navapp.buscador.onCreate(buscador.java:51)
  137. at android.app.Activity.performCreate(Activity.java:5447)
  138. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
Add Comment
Please, Sign In to add comment