毕加索正在加载URL,但未显示图片

问题描述 投票:1回答:1

到目前为止,我遇到了最奇怪的问题之一。我正在创建一个应用程序,通过不同的活动发送有关书籍和作者的信息。我在意图的帮助下向他们发送邮件。我的问题在作者部分中。我要发送姓名,年龄和图片。名称和年龄已成功发送,据我所知,调试器也成功发送了图像。但是,毕加索拒绝将其加载到ImageView中。没有显示任何错误,我也不知道发生了什么。这是一些代码。

此功能重置我数据库中的信息:

public void resetAuthor()
    {
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("DELETE FROM " + TABLE_NAME_AUTHORS);
        db.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + TABLE_NAME_AUTHORS + "'");

        addBegginingInfoAuthor("J.K.Rowling", 54, "https://www.biographyonline.net/wp-content/uploads/2014/05/jk-rowling4.jpg");
        addBegginingInfoAuthor("J.R.R. Tolken", 81, "https://www.biography.com/.image/t_share/MTE5NTU2MzE2Mzg4MzYxNzM5/jrr-tolkien-9508428-1-402.jpg");
        addBegginingInfoAuthor("Arthur Conan Doyle", 71, "https://upload.wikimedia.org/wikipedia/commons/b/bd/Arthur_Conan_Doyle_by_Walter_Benington%2C_1914.png");
    }

AuthorAdapter类。这是我的回收者视图的适配器,该适配器显示有关作者的详细信息。这也是我开始进行其他活动的意图:

@Override
    public void onBindViewHolder(@NonNull AuthorsViewHolder holder, int position) {
        if (!mCursor.moveToPosition(position))
        {
            return;
        }

        final int author_id = mCursor.getInt(mCursor.getColumnIndex(DatabaseHelper.AUTHORS_COL_1));
        final String name = mCursor.getString(mCursor.getColumnIndex(DatabaseHelper.AUTHORS_COL_2));
        final String age = mCursor.getString(mCursor.getColumnIndex(DatabaseHelper.AUTHORS_COL_3));
        final String image = mCursor.getString(mCursor.getColumnIndex(DatabaseHelper.AUTHORS_COL_4));

        holder.authorIndex.setText(String.valueOf(author_id));
        holder.authorName.setText(name);
        holder.authorAge.setText(String.valueOf(age));
        holder.authorName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), displayBooksFromAuthor.class);
                intent.putExtra("Author_id", author_id);
                intent.putExtra("Author_name", name);
                intent.putExtra("Author_age", age);
                intent.putExtra("Author_image", image);
                mContext.startActivity(intent);
            }
        });
    }

最后,我的DisplayAuthorDetails类从意图接收数据并显示它:

int author_id = intent.getIntExtra("Author_id", 0);
        String author_name = intent.getStringExtra("Author_name");
        String author_age = intent.getStringExtra("Author_age");
        String author_picture = intent.getStringExtra("Author_image");

        et_name.setText(author_name);
        et_age.setText(author_age);
        et_id.setText(String.valueOf(author_id));
        Picasso.get().load(author_picture).into(author_image);

我具有库依赖关系,还有清单文件中的两个权限

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

implementation 'com.squareup.picasso:picasso:2.71828

此问题最奇怪的部分是,当我创建一个全新的项目并尝试加载图像时,它会成功加载。任何帮助表示赞赏。谢谢您的时间

编辑

DatabaseHelper类:

public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "Books and Authors.db";
    public static final String TABLE_NAME_AUTHORS = "Authors_table";
    public static final String AUTHORS_COL_1 = "Author_ID";
    public static final String AUTHORS_COL_2 = "Name";
    public static final String AUTHORS_COL_3 = "Age";
    public static final String AUTHORS_COL_4 = "Author_picture";
    public static final String TABLE_NAME_BOOKS = "Books_table";
    public static final String BOOKS_COL_1 = "Book_ID";
    public static final String BOOKS_COL_2 = "Author_Foreign";
    public static final String BOOKS_COL_3 = "Title";
    public static final String BOOKS_COL_4 = "Price";


    public DatabaseHelper(Context context) {

        super(context, DATABASE_NAME, null, 2);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("create table " + TABLE_NAME_BOOKS + " (Book_ID INTEGER PRIMARY KEY AUTOINCREMENT, Title TEXT," + "Author_Foreign INT," + "Price TEXT)");
        db.execSQL("create table " + TABLE_NAME_AUTHORS + " (Author_ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT," + "Age INTEGER," + "Author_picture TEXT)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_AUTHORS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_BOOKS);
        onCreate(db);
    }

    public boolean insertDataBooks(String title, float price) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(BOOKS_COL_3, title);
        contentValues.put(BOOKS_COL_4, price);


        long result = db.insert(TABLE_NAME_BOOKS, null, contentValues);


        if (result == 1) {
            return false;
        } else {
            return true;
        }
    }

    public boolean insertDataAuthors(String name, int age) {
        SQLiteDatabase mydb = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(AUTHORS_COL_2, name);
        contentValues.put(AUTHORS_COL_3, age);

        long result = mydb.insert(TABLE_NAME_AUTHORS, null, contentValues);

        if (result == 1) {
            return false;
        } else {
            return true;
        }
    }

    public boolean addBegginingInfo(int foreign_author_id, String title, double price) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(BOOKS_COL_2, foreign_author_id);
        contentValues.put(BOOKS_COL_3, title);
        contentValues.put(BOOKS_COL_4, price);

        long result = db.insert(TABLE_NAME_BOOKS, null, contentValues);

        if (result == 1) {
            return false;
        } else {
            return true;
        }
    }

    public boolean addBegginingInfoAuthor(String name, int age, String image)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(AUTHORS_COL_2, name);
        contentValues.put(AUTHORS_COL_3, age);
        contentValues.put(AUTHORS_COL_4, image);

        long result = db.insert(TABLE_NAME_AUTHORS, null, contentValues);

        if (result == 1) {
            return false;
        } else {
            return true;
        }
    }

    public Integer deleteBook(String index) {
        SQLiteDatabase db = this.getWritableDatabase();
        return db.delete(TABLE_NAME_BOOKS, "Book_ID = ?", new String[]{index});
    }

    public Integer deleteAuthor(String authorIndex) {
        SQLiteDatabase db = this.getWritableDatabase();
        return db.delete(TABLE_NAME_AUTHORS, "Author_ID = ?", new String[]{authorIndex});
    }

    public void resetBookTable() {
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("DELETE FROM " + TABLE_NAME_BOOKS);
        db.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + TABLE_NAME_BOOKS + "'");

        addBegginingInfo(1, "Harry Potter", 9.99);
        addBegginingInfo(1, "Fantastic Beasts", 14.99);
        addBegginingInfo(2, "Lord of the Rings", 8.99);
        addBegginingInfo(2, "The Hobbit", 12.99);
        addBegginingInfo(3, "Sherlock Holmes", 6.99);
        addBegginingInfo(3, "Valley of Fear", 7.99);


    }

    public void resetAuthor()
    {
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("DELETE FROM " + TABLE_NAME_AUTHORS);
        db.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + TABLE_NAME_AUTHORS + "'");

        addBegginingInfoAuthor("J.K.Rowling", 54, "https://www.biographyonline.net/wp-content/uploads/2014/05/jk-rowling4.jpg");
        addBegginingInfoAuthor("J.R.R. Tolken", 81, "https://www.biography.com/.image/t_share/MTE5NTU2MzE2Mzg4MzYxNzM5/jrr-tolkien-9508428-1-402.jpg");
        addBegginingInfoAuthor("Arthur Conan Doyle", 71, "https://upload.wikimedia.org/wikipedia/commons/b/bd/Arthur_Conan_Doyle_by_Walter_Benington%2C_1914.png");
    }
}
java android picasso
1个回答
0
投票

经过数小时的尝试,我终于发现要解决此问题,我只需要在模拟器上重新安装该应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.