Se mettre “par Défaut FirebaseApp n'est pas initialisé dans ce processus de” en dépit de l'initialisation de FirebaseApp tout en utilisant FirebaseStorage
Je suis en train de télécharger des images à l'aide de Firebase de Stockage. J'ai écrit le code suivant
MainActivity.java
public class MainActivity extends AppCompatActivity {
ArrayList<Car> carListSuper;
RecyclerView rvCarList;
ProgressBar progressbar;
private CarListAdapter carListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
carListSuper = new ArrayList<>();
Firebase myFirebaseRef = new Firebase("https://carbar-7dae7.firebaseio.com/");
rvCarList = (RecyclerView) findViewById(R.id.rvCarList);
rvCarList.setItemAnimator(new FeedItemAnimator());
progressbar = (ProgressBar) findViewById(R.id.progressCarLoad);
carListAdapter = new CarListAdapter(carListSuper,MainActivity.this);
RecyclerView.LayoutManager linearLayoutManager = new LinearLayoutManager(this);
rvCarList.setLayoutManager(linearLayoutManager);
rvCarList.setAdapter(carListAdapter);
myFirebaseRef.child("carList").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Log.i("saz",snapshot.getValue().toString());
progressbar.setVisibility(View.GONE);
carListSuper.clear();
//String jsonString = snapshot.getValue().toString();
try {
for (int i=0; i<snapshot.getChildrenCount();i++) {
//Car carList = gson.fromJson(snapshot.child(i+""), Car.class);
DataSnapshot snap = snapshot.child(i+"");
carListSuper.add(FirebaseParser.carParser(snap));
}
carListAdapter.updatelist(carListSuper);
Log.i("saz",snapshot.getValue().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override public void onCancelled(FirebaseError error) { }
});
}
CarListAdapter.java
public class CarListAdapter<T> extends RecyclerView.Adapter<CarListAdapter.ViewHolder> {
static int i = 0;
private static Context m_context;
List<Car> carList = null;
public static final int VIEW_TYPE_DEFAULT = 1;
public static final int VIEW_TYPE_LOADER = 2;
//Provide a suitable constructor (depends on the kind of dataset)
public CarListAdapter(List<Car> carList, Context context) {
Log.i("saz", "dealerCircularCalls: " + this.carList);
this.carList = carList;
m_context = context;
}
//Create new views (invoked by the layout manager)
@Override
public CarListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//create a new view
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.car_item, parent, false);
//set the view's size, margins, paddings and layout parameters
ViewHolder vh = new ViewHolder(v);
return vh;
}
public void updatelist(ArrayList<Car> list) {
ArrayList tempList = new ArrayList();
tempList.addAll(list);
Log.i("saz", "Size on notifyupdate: " + list.size());
carList.clear();
carList.addAll(tempList);
notifyDataSetChanged();
}
//Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
//- get element from your dataset at this position
//- replace the contents of the view with that element
Log.i("saz", "position rv: " + position);
/*if (position % 2 != 0) {
holder.cv.setCardBackgroundColor(m_context.getResources().getColor(R.color.lighter_gray));
} else {
holder.cv.setCardBackgroundColor(m_context.getResources().getColor(R.color.white));
}*/
/*CarBarDb db = new CarBarDb(m_context,
CarBarDb.DATABASE_NAME, null, CarBarDb.DATABASE_VERSION);*/
Car car = carList.get(position);
holder.provider.setText("Zoomcar");
holder.carType.setText(car.getCarType());
holder.carName.setText(car.getCarName());
holder.tarrif.setText(car.getPrice_per_hour_weekday());
if (m_context!=null) {
FirebaseStorage storage = FirebaseStorage.getInstance(FirebaseApp.initializeApp(m_context));
StorageReference storageRef = storage.getReferenceFromUrl("gs://carbar-7dae7.appspot.com/");
storageRef.child("CarImages/figo.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Picasso.with(m_context).load(uri)
.error(R.drawable.no_image)
.into(holder.imCarImage);
}
});
}
//db.close();
}
//Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
Log.i("saz", "carList.size(): " + carList.size());
return carList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
//each data item is just a string in this case
CardView cv;
TextView provider;
TextView carName;
TextView carType;
TextView tarrif;
ImageButton imCarImage;
public ViewHolder(final View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cvCarItem);
provider = (TextView) cv.findViewById(R.id.tvProvider);
carName = (TextView) cv.findViewById(R.id.tvCarName);
carType = (TextView) cv.findViewById(R.id.tvCarType);
tarrif = (TextView) cv.findViewById(R.id.tvTarrif);
imCarImage = (ImageButton) cv.findViewById(R.id.imgCarImage);
}
}
Encore, j'obtiens l'erreur suivante.
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.saz.firebasetest. Make sure to call FirebaseApp.initializeApp(Context) first.
Et dans l'activité principale, j'initialise cette carte comme
carListAdapter = new CarListAdapter(carListSuper,MainActivity.this);
J'ai cherché sur ce forum mais n'ont pas quelle est la cause exacte. S'il vous plaît aider.
Les lignes du journal:
FATAL EXCEPTION: main
Process: com.saz.firebasetest, PID: 6991
java.lang.IllegalArgumentException: Null is not a valid value for the FirebaseApp.
at com.google.android.gms.common.internal.zzac.zzb(Unknown Source)
at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source)
at com.saz.firebasetest.controller.CarListAdapter.onBindViewHolder(CarListAdapter.java:86)
at com.saz.firebasetest.controller.CarListAdapter.onBindViewHolder(CarListAdapter.java:29)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5768)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5801)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5037)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4913)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3260)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3069)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3518)
at android.view.View.layout(View.java:16975)
at android.view.ViewGroup.layout(ViewGroup.java:5579)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:16975)
at android.view.ViewGroup.layout(ViewGroup.java:5579)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:16975)
at android.view.ViewGroup.layout(ViewGroup.java:5579)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:433)
at android.view.View.layout(View.java:16975)
at android.view.ViewGroup.layout(ViewGroup.java:5579)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:16975)
at android.view.ViewGroup.layout(ViewGroup.java:5579)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1844)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1753)
at android.view.View.layout(View.java:16975)
at android.view.ViewGroup.layout(ViewGroup.java:5579)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2755)
at android.view.View.layout(View.java:16975)
at android.view.ViewGroup.layout(ViewGroup.java:5579)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2552)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2255)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6737)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894)
at android.view.Choreographer.doCallbacks(Choreographer.java:696)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
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.
--------- beginning of system
Avez-vous enregistré votre demande sur Firebase console ?
Oui. J'ai créé le projet sur Firebase. Aussi téléchargé les fichiers d'image dans le projet. Je suis déjà à l'aide de la base de données des services sans aucun problème.
Oui. J'ai créé le projet sur Firebase. Aussi téléchargé les fichiers d'image dans le projet. Je suis déjà à l'aide de la base de données des services sans aucun problème.
OriginalL'auteur Sarfaraz | 2016-09-29
Vous devez vous connecter pour publier un commentaire.
Vous êtes de mélange Firebase versions du SDK.
Cela provient d'une Firebase 2.x SDK:
Mais Firebase de Stockage est inclus uniquement dans Firebase 9.x.
Vous aurez besoin de passer à un seul Firebase version du SDK. Étant donné que vous souhaitez utiliser Firebase de Stockage, qui sera la version 9.x.
Si vous suivez les des instructions sur la firebase.google.com, vous pouvez voir les dépendances de la Base de données et le Stockage sont:
Si vous utilisez exactement 9.6.1 n'a pas beaucoup d'importance, mais les versions doivent être les mêmes, alors que vous avez probablement inclure la base de données via
compile 'com.firebase:firebase-client-android:2.5.2+'
.classpath 'com.google.gms:google-services:3.0.0'
dans mon projet gradle etcompile 'com.google.android.gms:play-services:9.8.0' compile 'com.google.firebase:firebase-core:9.8.0'
dans mon application gradle. J'obtiens la même erreur.Avez-vous mis le google-services.fichier json dans le dossier app. Assurez-vous également que vous avez appliqué le plugin par
apply plugin: 'com.google.gms.google-services'
dans la construction.gradle (en vertu de l'application). Espérons que cela aide.OriginalL'auteur Frank van Puffelen
Semble vous effectuez les opérations suivantes:
Que devrait être la suivante:
Dans votre activité
et comme suggestion, je ne ferais pas
dans le onBindViewHolder méthode. Serait-ce faire dans le constructeur et d'en faire une variable de classe.
Vous pouvez passer la ligne du journal? Il semble que votre m_context est nulle? Est-ce possible?
J'Ai donné la valeur null est à vérifier. Fixation de la complète des journaux en question.
OK pense que c'est le problème, j'ai mis à jour ma réponse
OriginalL'auteur QVDev
Veuillez ajouter la ligne ci-dessous dans votre carte du constructeur pour initialiser-il pas à l'intérieur de bindviewholder méthode.
Pouvez vous s'il vous plaît poster un peu plus de code de votre activité? Afin que je puisse analyser votre problème. Est
FirebaseApp.initializeApp(m_context);
FirebaseApp votre propre classe ?J'ai édité la question. Ont donné CarListAdapter.java classe. À partir de MainActivity.java je suis juste l'initialisation de cette carte. Veuillez vérifier.
Je ne pense pas que si il y a un problème dans votre carte. Le seul problème est dans votre MainActivity. S'il vous plaît poster.
Mise à jour
OriginalL'auteur GrIsHu