0

Included the Picasso library from @Droidman. The library is really good. But if I am announcing something wrong, or I am not displaying the picture correctly on the screen. I understand correctly, I can use the object with the received ID in the .into () method? Maybe I haven't connected the library to the end.

package com.example.my_ugf;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;

public class MainActivity extends AppCompatActivity {
//final public String URL_poster = "https://udmfil.ru/";
public ImageView imageview_poster;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    imageview_poster.findViewById(R.id.imageview_poster);
    Picasso.get().load("/upload/iblock/95a/95aa56e9694ebd46e2855e7167966cfd.jpg")
            .resize(50, 50)
            .centerCrop()
            .into(imageview_poster);
}
}

This is what the log produces.

2021-11-17 09:46:20.345 29475-29475/com.example.my_ugf E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2021-11-17 09:46:20.363 29475-29552/com.example.my_ugf E/Perf: Fail to get file list com.example.my_ugf
2021-11-17 09:46:20.367 29475-29552/com.example.my_ugf E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-11-17 09:46:20.451 29475-29475/com.example.my_ugf D/View: com.example.my_ugf initForcedUseForceDark: 1
2021-11-17 09:46:20.614 29475-29475/com.example.my_ugf D/AndroidRuntime: Shutting down VM
2021-11-17 09:46:20.616 29475-29475/com.example.my_ugf E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.my_ugf, PID: 29475
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.my_ugf/com.example.my_ugf.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.ImageView.findViewById(int)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(Unknown Source:621)
    at android.app.ActivityThread.handleLaunchActivity(Unknown Source:47)
    at android.app.servertransaction.LaunchActivityItem.execute(Unknown Source:63)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(Unknown Source:77)
    at android.app.servertransaction.TransactionExecutor.execute(Unknown Source:73)
    at android.app.ActivityThread$H.handleMessage(Unknown Source:43)
    at android.os.Handler.dispatchMessage(Unknown Source:19)
    at android.os.Looper.loop(Unknown Source:242)
    at android.app.ActivityThread.main(Unknown Source:98)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11)
    at com.android.internal.os.ZygoteInit.main(Unknown Source:275)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.ImageView.findViewById(int)' on a null object reference
    at com.example.my_ugf.MainActivity.onCreate(MainActivity.java:18)
    at android.app.Activity.performCreate(Unknown Source:19)
    at android.app.Activity.performCreate(Unknown Source:1)
    at android.app.Instrumentation.callActivityOnCreate(Unknown Source:3)
    at android.app.ActivityThread.performLaunchActivity(Unknown Source:376)
    at android.app.ActivityThread.handleLaunchActivity(Unknown Source:47) 
    at android.app.servertransaction.LaunchActivityItem.execute(Unknown Source:63) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(Unknown Source:77) 
    at android.app.servertransaction.TransactionExecutor.execute(Unknown Source:73) 
    at android.app.ActivityThread$H.handleMessage(Unknown Source:43) 
    at android.os.Handler.dispatchMessage(Unknown Source:19) 
    at android.os.Looper.loop(Unknown Source:242) 
    at android.app.ActivityThread.main(Unknown Source:98) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11) 
    at com.android.internal.os.ZygoteInit.main(Unknown Source:275) 
2021-11-17 09:46:20.624 29475-29475/com.example.my_ugf E/MQSEventManagerDelegate: failed to get MQSService.
2021-11-17 09:46:20.625 29475-29475/? D/OOMEventManagerFK: checkEventAndDumpForJE: 0
2021-11-17 09:46:20.625 29475-29475/? E/MQSEventManagerDelegate: failed to get MQSService.
2021-11-17 09:46:20.653 29475-29475/? I/Process: Sending signal. PID: 29475 SIG: 9
2021-11-17 09:46:19.865 29475-29475/? I/.example.my_ug: Late-enabling -Xcheck:jni
2021-11-17 09:46:19.894 29475-29475/? E/.example.my_ug: Unknown bits set in runtime_flags: 0x8000
2021-11-17 09:46:19.865 29475-29475/? I/.example.my_ug: Late-enabling -Xcheck:jni
2021-11-17 09:46:19.894 29475-29475/? E/.example.my_ug: Unknown bits set in runtime_flags: 0x8000
2021-11-17 09:46:19.865 29475-29475/? I/.example.my_ug: Late-enabling -Xcheck:jni
2021-11-17 09:46:19.894 29475-29475/? E/.example.my_ug: Unknown bits set in runtime_flags: 0x8000
  • 1
    `String getUrlImage(String vol){ ... return null;}` <- You always return null as your Image URL. – OH GOD SPIDERS Nov 15 '21 at 14:10
  • 1
    I suggest you take a look at my (dated, but still valid) [post](https://stackoverflow.com/questions/15549421/how-to-download-and-save-an-image-in-android) about image downloading. TL;DR just use Picasso or Glide (and do NOT use AsyncTasks because it's 2021 and not 2011 - use RxJava or Kotlin coroutines for threading) – Droidman Nov 15 '21 at 14:27
  • I realized that I was not correctly finding the object in the MainActivity. Incorrectly using "imageview_poster.findViewById (R.id.imageview_poster);" – Сергей Дёшин Nov 17 '21 at 06:23

1 Answers1

0

The exception is

Caused by: java.lang.NullPointerException: println needs a message

which is happening through a Log.i call - you're passing null in as the message parameter, which isn't allowed. Since you're null-checking vol before calling the gtUrlImage method, I'm guessing it's happening here:

    // arg array is full of nulls
    String[] arg = new String[10];
    ...
    // index is 20 (-1 + 21) if this sequence wasn't found
    index = poster.indexOf("m-img buy") + 21;
    ...
    // array entry is only set if index is not 20, i.e. if that sequence was found
    if (index!=20) arg[i]= poster.substring(index, index + 55);
    // if the sequence wasn't found, arg[i] is still null
    Log.i("UGF",arg[i]);

So basically, if you read a line that doesn't contain "m-img buy" then that Log line crashes. You'll have to work out why you're getting those lines the second time around, and work out how to handle them - or just avoid logging them (or use String.valueOf(arg[i]) to safely convert the null to a string)

cactustictacs
  • 17,935
  • 2
  • 14
  • 25