我正在使用一个simplecursortreeadapter将来自外部sqlite数据库的检索数据调整为expendablelistview。我正在使用一个viewbinder来调整视图。在添加第三个块(滑行所在)之前,该应用程序运行正常。.但是在添加块后..,应用程序停止了。
公共类MyViewBinder实现SimpleCursorTreeAdapter.ViewBinder {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
int viewID = view.getId();
switch(viewID){
case R.id.group1 :
TextView groupName = (TextView) view;
String groupname;
groupname = cursor.getString(cursor.getColumnIndex(Database.DATABASE_GROUP_1));
groupName.setText(groupname);
break;
case R.id.child1 :
TextView friendName = (TextView) view;
String friend_name;
friend_name = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_1));
friendName.setText(friend_name);
break;
case R.id.child2 :
ImageView contactProfile = (ImageView) view;
byte[] imageBytes = cursor.getBlob(cursor.getColumnIndex(Database.DATABASE_CHILD_2));
if(imageBytes != null ){
// Pic image from database
contactProfile.setImageBitmap(BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length));
}else {
// If image not found in database , assign a default image
contactProfile.setBackgroundResource(0);
}
break;
case R.id.child3 :
String urls;
urls = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_3));
ImageView url=findViewById(R.id.child3);
Glide.with(MainActivity.this).load(urls).into(url);
break;
}
return true;
}
构建成功并且打开了应用程序,但是当我单击某个东西时,应用程序停止了..这是我的错误消息:
08-01 18:40:20.512 4772-4772/ma.ac.iav.databasewithjava D/AndroidRuntime: Shutting down VM
08-01 18:40:20.585 4772-4772/ma.ac.iav.databasewithjava E/AndroidRuntime: FATAL EXCEPTION: main
Process: ma.ac.iav.databasewithjava, PID: 4772
java.lang.NullPointerException: Argument must not be null
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:31)
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:25)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:651)
at ma.ac.iav.databasewithjava.MainActivity$MyViewBinder.setViewValue(MainActivity.java:99)
at android.widget.SimpleCursorTreeAdapter.bindView(SimpleCursorTreeAdapter.java:220)
at android.widget.SimpleCursorTreeAdapter.bindChildView(SimpleCursorTreeAdapter.java:254)
at android.widget.CursorTreeAdapter.getChildView(CursorTreeAdapter.java:251)
at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
at android.widget.AbsListView.obtainView(AbsListView.java:2372)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillSpecific(ListView.java:1494)
at android.widget.ListView.layoutChildren(ListView.java:1790)
at android.widget.AbsListView.onLayout(AbsListView.java:2171)
at android.view.View.layout(View.java:19590)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19590)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19590)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443)
at android.view.View.layout(View.java:19590)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19590)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19590)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:758)
at android.view.View.layout(View.java:19590)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2484)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2200)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
这是我正在使用的版本:
实现'com.github.bumptech.glide:glide:4.7.1' 注解处理器'com.github.bumptech.glide:compiler:4.7.1'
答案 0 :(得分:1)
检查imageView是否为空
答案 1 :(得分:0)
检查您的查询urls
是否为null
。
此行:
urls = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_3));
答案 2 :(得分:0)
崩溃源于:
ImageView url=findViewById(R.id.child3);
Glide.with(MainActivity.this).load(urls).into(url);
因为url为null; 检查您的“ R.id.child3”
答案 3 :(得分:0)
使用以下代码在项目中设置@GlideModule
import android.content.Context;
import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
import com.firebase.ui.storage.images.FirebaseImageLoader;
import com.google.firebase.storage.StorageReference;
import java.io.InputStream;
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
super.registerComponents(context, glide, registry);
registry.append(StorageReference.class, InputStream.class, new FirebaseImageLoader.Factory());
}
}
现在,在整个项目中使用GlideApp
代替Glide
。