我在过去两天收到此错误并且我无法弄清楚如何解决它,我需要将数据(图像)存储在firebase中作为我的Android应用程序中的列表视图我正在使用RecycleView;
这是主要课程:
public class MainActivityPersistent extends AppCompatActivity {
private static final String G_DB_URL = "https://fir-test-ca03d.firebaseio.com/tutorial/list";
//where the data stored in the firebase
private boolean isEnabled;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(!isEnabled) {
try {
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
isEnabled = true;
} catch (RuntimeException e) { }
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.list);
final ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mProgressBar.setVisibility(View.VISIBLE);
LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager( this );
mRecyclerView.setLayoutManager(mLinearLayoutManager);
DatabaseReference ref = FirebaseDatabase.getInstance().getReferenceFromUrl(G_DB_URL);
FirebaseRecyclerAdapter<DataModel, ListRowHolder> mAdapter = new FirebaseRecyclerAdapter<DataModel, ListRowHolder>(
DataModel.class,
R.layout.list_row_item, ListRowHolder.class, ref
) {
@Override protected void populateViewHolder(final ListRowHolder viewHolder,
DataModel model, int position) {
mProgressBar.setVisibility(View.GONE);
final StorageReference ref = FirebaseStorage.getInstance().getReferenceFromUrl(model.image);
viewHolder.description.setText(model.description);
Glide.with(MainActivityPersistent.this)
.using(new FirebaseImageLoader())
.load(ref)
.into(viewHolder.image);
}
};
}
}
这是我运行应用时遇到的错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapplication, PID: 21238
java.lang.IllegalArgumentException: The storage Uri could not be parsed.
at com.google.firebase.storage.FirebaseStorage.getReferenceFromUrl(Unknown Source)
at com.myapplication.MainActivityPersistent$1.populateViewHolder(MainActivityPersistent.java:54)
at com.myapplication.MainActivityPersistent$1.populateViewHolder(MainActivityPersistent.java:47)
at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:218)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6400)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6433)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5377)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5640)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5482)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5478)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2215)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1542)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1502)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3625)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3354)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3886)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2246)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1968)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6388)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer
答案 0 :(得分:1)
FirebaseDatabase.getInstance().getReference(G_DB_URL);
从您的firebase参考
更改此内容答案 1 :(得分:0)
找到简单的解决方案只需更换:
StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(sponsors.getLogoLink());
Glide.with(mContext)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(sponsorLogo);
简单:
Glide.with(mContext)
.load(sponsors.getLogoLink())
.into(sponsorLogo);
解决了我的问题