0

I am trying to fetch data from an API, but keep getting this error 'this is my json data'

{
"page": 1,
"results": [
    {
        "adult": false,
        "backdrop_path": "/y5Z0WesTjvn59jP6yo459eUsbli.jpg",
        "genre_ids": [
            27,
            53
        ],
        "id": 663712,
        "original_language": "en",
        "original_title": "Terrifier 2",
        "overview": "After being resurrected by a sinister entity, Art the Clown returns to Miles County where he must hunt down and destroy a teenage girl and her younger brother on Halloween night.  As the body count rises, the siblings fight to stay alive while uncovering the true nature of Art's evil intent.",
        "popularity": 7866.782,
        "poster_path": "/b6IRp6Pl2Fsq37r9jFhGoLtaqHm.jpg",
        "release_date": "2022-10-06",
        "title": "Terrifier 2",
        "video": false,
        "vote_average": 7.1,
        "vote_count": 445
    },
    {
        "adult": false,
        "backdrop_path": "/bQXAqRx2Fgc46uCVWgoPz5L5Dtr.jpg",
        "genre_ids": [
            28,
            14,
            878
        ],
        "id": 436270,
        "original_language": "en",
        "original_title": "Black Adam",
        "overview": "Nearly 5,000 years after he was bestowed with the almighty powers of the Egyptian gods—and imprisoned just as quickly—Black Adam is freed from his earthly tomb, ready to unleash his unique form of justice on the modern world.",
        "popularity": 4428.609,
        "poster_path": "/3zXceNTtyj5FLjwQXuPvLYK5YYL.jpg",
        "release_date": "2022-10-19",
        "title": "Black Adam",
        "video": false,
        "vote_average": 6.9,
        "vote_count": 905
    },
    {
        "adult": false,
        "backdrop_path": "/pGx6O6IwqADOsgmqWzPysmWnOyr.jpg",
        "genre_ids": [
            28,
            14
        ],
        "id": 732459,
        "original_language": "en",
        "original_title": "Blade of the 47 Ronin",
        "overview": "In this sequel to \"47 Ronin,\" a new class of warriors emerges among the Samurai clans to keep a sought-after sword from falling into the wrong hands.",
        "popularity": 3821.739,
        "poster_path": "/kjFDIlUCJkcpFxYKtE6OsGcAfQQ.jpg",
        "release_date": "2022-10-25",
        "title": "Blade of the 47 Ronin",
        "video": false,
        "vote_average": 6.7,
        "vote_count": 47
    },
    {
        "adult": false,
        "backdrop_path": "/naNXYdBzTEb1KwOdi1RbBkM9Zv1.jpg",
        "genre_ids": [
            27,
            53
        ],
        "id": 420634,
        "original_language": "en",
        "original_title": "Terrifier",
        "overview": "On Halloween night, a young woman finds herself as the obsession of a sadistic murderer known as Art the Clown.",
        "popularity": 3031.419,
        "poster_path": "/6PQqC4SbY910VvyVad6mvsboILU.jpg",
        "release_date": "2016-10-15",
        "title": "Terrifier",
        "video": false,
        "vote_average": 6.6,
        "vote_count": 889
    },
    {
        "adult": false,
        "backdrop_path": "/b2FxWOxe9K7ZZ1uaPOze2RJ1ajq.jpg",
        "genre_ids": [
            27,
            28,
            35
        ],
        "id": 675054,
        "original_language": "es",
        "original_title": "MexZombies",
        "overview": "A group of teenagers must face a zombie apocalypse, and help reestablish order.",
        "popularity": 2784.235,
        "poster_path": "/pTxw4GFE3ZfzJfvuUsPyD5njAuI.jpg",
        "release_date": "2022-10-26",
        "title": "MexZombies",
        "video": false,
        "vote_average": 7.3,
        "vote_count": 49
    },
    {
        "adult": false,
        "backdrop_path": "/1DBDwevWS8OhiT3wqqlW7KGPd6m.jpg",
        "genre_ids": [
            53
        ],
        "id": 985939,
        "original_language": "en",
        "original_title": "Fall",
        "overview": "For best friends Becky and Hunter, life is all about conquering fears and pushing limits. But after they climb 2,000 feet to the top of a remote, abandoned radio tower, they find themselves stranded with no way down. Now Becky and Hunter’s expert climbing skills will be put to the ultimate test as they desperately fight to survive the elements, a lack of supplies, and vertigo-inducing heights",
        "popularity": 2350.808,
        "poster_path": "/spCAxD99U1A6jsiePFoqdEcY0dG.jpg",
        "release_date": "2022-08-11",
        "title": "Fall",
        "video": false,
        "vote_average": 7.3,
        "vote_count": 1650
    },
    {
        "adult": false,
        "backdrop_path": "/tIX6j3NzadlwGcJ52nuWdmtOQkg.jpg",
        "genre_ids": [
            27,
            53,
            9648
        ],
        "id": 717728,
        "original_language": "en",
        "original_title": "Jeepers Creepers: Reborn",
        "overview": "Forced to travel with her boyfriend to a horror festival, Laine begins to experience disturbing visions associated with the urban legend of The Creeper. As the festival arrives and the blood-soaked entertainment builds to a frenzy, she becomes the center of it while something unearthly has been summoned.",
        "popularity": 2184.802,
        "poster_path": "/aGBuiirBIQ7o64FmJxO53eYDuro.jpg",
        "release_date": "2022-09-15",
        "title": "Jeepers Creepers: Reborn",
        "video": false,
        "vote_average": 5.7,
        "vote_count": 430
    },
    {
        "adult": false,
        "backdrop_path": "/iS9U3VHpPEjTWnwmW56CrBlpgLj.jpg",
        "genre_ids": [
            14,
            35,
            10751
        ],
        "id": 642885,
        "original_language": "en",
        "original_title": "Hocus Pocus 2",
        "overview": "29 years since the Black Flame Candle was last lit, the 17th-century Sanderson sisters are resurrected, and they are looking for revenge. Now it's up to three high school students to stop the ravenous witches from wreaking a new kind of havoc on Salem before dawn on All Hallow's Eve.",
        "popularity": 1959.906,
        "poster_path": "/7ze7YNmUaX81ufctGqt0AgHxRtL.jpg",
        "release_date": "2022-09-27",
        "title": "Hocus Pocus 2",
        "video": false,
        "vote_average": 7.6,
        "vote_count": 1036
    },
    {
        "adult": false,
        "backdrop_path": "/bJa3RcFKgtVKJqTJCSSuBQeP9c8.jpg",
        "genre_ids": [
            27
        ],
        "id": 86328,
        "original_language": "en",
        "original_title": "Terrifier",
        "overview": "After witnessing a brutal murder on Halloween night, a young woman becomes the next target of a maniacal entity.",
        "popularity": 1969.59,
        "poster_path": "/gb6rq2nD0jRrN0dCzigg2MxXNsB.jpg",
        "release_date": "2011-08-09",
        "title": "Terrifier",
        "video": false,
        "vote_average": 6.5,
        "vote_count": 42
    },
    {
        "adult": false,
        "backdrop_path": "/5GA3vV1aWWHTSDO5eno8V5zDo8r.jpg",
        "genre_ids": [
            27,
            53
        ],
        "id": 760161,
        "original_language": "en",
        "original_title": "Orphan: First Kill",
        "overview": "After escaping from an Estonian psychiatric facility, Leena Klammer travels to America by impersonating Esther, the missing daughter of a wealthy family. But when her mask starts to slip, she is put against a mother who will protect her family from the murderous “child” at any cost.",
        "popularity": 2009.304,
        "poster_path": "/pHkKbIRoCe7zIFvqan9LFSaQAde.jpg",
        "release_date": "2022-07-27",
        "title": "Orphan: First Kill",
        "video": false,
        "vote_average": 6.8,
        "vote_count": 1243
    },
    {
        "adult": false,
        "backdrop_path": "/etP5jwlwvkNhwe7jnI2AyA6ZKrR.jpg",
        "genre_ids": [
            878
        ],
        "id": 575322,
        "original_language": "en",
        "original_title": "Звёздный разум",
        "overview": "After depleting Earth's resources for centuries, humankind's survival requires an exodus to outer space. An international expedition is quickly formed to find a suitable new planet, but when plans go awry, the crew is suddenly stranded without power on a strange planet, where something unimaginable lies in wait.",
        "popularity": 1881.821,
        "poster_path": "/rFljUdOozFEv6HDHIFpFvcYW0ec.jpg",
        "release_date": "2022-01-06",
        "title": "Project Gemini",
        "video": false,
        "vote_average": 5.6,
        "vote_count": 153
    },
    {
        "adult": false,
        "backdrop_path": "/askg3SMvhqEl4OL52YuvdtY40Yb.jpg",
        "genre_ids": [
            10751,
            16,
            14,
            10402,
            35,
            12
        ],
        "id": 354912,
        "original_language": "en",
        "original_title": "Coco",
        "overview": "Despite his family’s baffling generations-old ban on music, Miguel dreams of becoming an accomplished musician like his idol, Ernesto de la Cruz. Desperate to prove his talent, Miguel finds himself in the stunning and colorful Land of the Dead following a mysterious chain of events. Along the way, he meets charming trickster Hector, and together, they set off on an extraordinary journey to unlock the real story behind Miguel's family history.",
        "popularity": 1298.384,
        "poster_path": "/gGEsBPAijhVUFoiNpgZXqRVWJt2.jpg",
        "release_date": "2017-10-27",
        "title": "Coco",
        "video": false,
        "vote_average": 8.2,
        "vote_count": 16442
    },
    {
        "adult": false,
        "backdrop_path": "/mMA2YNddowV8MZtxpbn0a7Yilum.jpg",
        "genre_ids": [
            10752,
            36,
            28,
            18
        ],
        "id": 928123,
        "original_language": "zh",
        "original_title": "长津湖之水门桥",
        "overview": "In the follow-up to \"The Battle At Lake Changjin\", brothers Wu Qianli and Wu Wanli undertake a new task for the People's Volunteer Army, defending a bridge part of the American troops' escape route from the advancing Chinese.",
        "popularity": 1612.433,
        "poster_path": "/ugiL6wIhl1OfPyv1gqLkTe45jLl.jpg",
        "release_date": "2022-02-01",
        "title": "The Battle at Lake Changjin: Water Gate Bridge",
        "video": false,
        "vote_average": 6.4,
        "vote_count": 23
    },
    {
        "adult": false,
        "backdrop_path": "/zt6sKnx9dEiRCb7oVMlfmmMGJMO.jpg",
        "genre_ids": [
            28,
            35,
            53
        ],
        "id": 718930,
        "original_language": "en",
        "original_title": "Bullet Train",
        "overview": "Unlucky assassin Ladybug is determined to do his job peacefully after one too many gigs gone off the rails. Fate, however, may have other plans, as Ladybug's latest mission puts him on a collision course with lethal adversaries from around the globe—all with connected, yet conflicting, objectives—on the world's fastest train.",
        "popularity": 1641.214,
        "poster_path": "/tVxDe01Zy3kZqaZRNiXFGDICdZk.jpg",
        "release_date": "2022-07-03",
        "title": "Bullet Train",
        "video": false,
        "vote_average": 7.5,
        "vote_count": 2208
    },
    {
        "adult": false,
        "backdrop_path": "/nnUQqlVZeEGuCRx8SaoCU4XVHJN.jpg",
        "genre_ids": [
            14,
            12,
            10751
        ],
        "id": 532639,
        "original_language": "en",
        "original_title": "Pinocchio",
        "overview": "A wooden puppet embarks on a thrilling adventure to become a real boy.",
        "popularity": 1605.793,
        "poster_path": "/g8sclIV4gj1TZqUpnL82hKOTK3B.jpg",
        "release_date": "2022-09-07",
        "title": "Pinocchio",
        "video": false,
        "vote_average": 6.7,
        "vote_count": 1025
    },
    {
        "adult": false,
        "backdrop_path": "/5hoS3nEkGGXUfmnu39yw1k52JX5.jpg",
        "genre_ids": [
            28,
            12,
            14
        ],
        "id": 960704,
        "original_language": "ja",
        "original_title": "鋼の錬金術師 完結編 最後の錬成",
        "overview": "The Elric brothers’ long and winding journey comes to a close in this epic finale, where they must face off against an unworldly, nationwide threat.",
        "popularity": 1682.088,
        "poster_path": "/AeyiuQUUs78bPkz18FY3AzNFF8b.jpg",
        "release_date": "2022-06-24",
        "title": "Fullmetal Alchemist: The Final Alchemy",
        "video": false,
        "vote_average": 6.3,
        "vote_count": 113
    },
    {
        "adult": false,
        "backdrop_path": "/tSxbUnrnWlR5dQvUgqMI7sACmFD.jpg",
        "genre_ids": [
            14,
            28,
            18
        ],
        "id": 779782,
        "original_language": "en",
        "original_title": "The School for Good and Evil",
        "overview": "Best friends Sophie and Agatha navigate an enchanted school for young heroes and villains — and find themselves on opposing sides of the battle between good and evil.",
        "popularity": 1489.276,
        "poster_path": "/6oZeEu1GDILdwezmZ5e2xWISf1C.jpg",
        "release_date": "2022-10-19",
        "title": "The School for Good and Evil",
        "video": false,
        "vote_average": 7.3,
        "vote_count": 502
    },
    {
        "adult": false,
        "backdrop_path": "/2iGUavwv86Hubv3V5Iq4qEQXDfE.jpg",
        "genre_ids": [
            18,
            53,
            27
        ],
        "id": 848058,
        "original_language": "es",
        "original_title": "Cerdita",
        "overview": "A bullied overweight teenager sees a glimpse of hope when her tormentors are brutally abducted by a mesmerizing stranger.",
        "popularity": 1551.583,
        "poster_path": "/8EIQAvJjXdbNDMmBtHtgGqbc09V.jpg",
        "release_date": "2022-10-07",
        "title": "Piggy",
        "video": false,
        "vote_average": 6.8,
        "vote_count": 167
    },.....

'this my adapter class'

public class DownAdapter extends RecyclerView.Adapter<DownAdapter.DownViewHolder> {
Context mContext;
List<Test> mData;



@NonNull
@Override
public DownViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
   View view = LayoutInflater.from(mContext).inflate(R.layout.download_item,viewGroup,false);

    return new DownViewHolder(view);
    
}

@Override
public void onBindViewHolder(@NonNull DownViewHolder downViewHolder, int i) {
    downViewHolder.title.setText(mData.get(i).getOriginal_title());
   //downViewHolder.poster_path.setImageResource(mData.get(i).getPoster_path());
   downViewHolder.summary.setText(mData.get(i).getOriginal_language());
   // Glide.with(mContext).load(mData.get(i).getPoster_path()).into(downViewHolder.poster_path);


}

@Override
public int getItemCount() {
    return mData.size();

}
public DownAdapter(Context mContext, List<Test> mData) {
    this.mContext = mContext;
    this.mData = mData;
}

public static class DownViewHolder extends RecyclerView.ViewHolder {

    //ImageView poster_path;
    TextView title ;
    TextView summary;
    public DownViewHolder(@NonNull View itemView) {
        super(itemView);
        //poster_path= itemView.findViewById(R.id.img_download);
        title = itemView.findViewById(R.id.down_title);
        summary= itemView.findViewById(R.id.summary);
    }
}

}

'this is my main activity code'

public class download extends AppCompatActivity {
private RecyclerView Rvdown;
ImageView DownmovieImg;
TextView Down_tv_title;
TextView Down_tv_summary;
List<Test> testList;
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE
};
//link for popular movies
private static String JSON_URL="https://api.themoviedb.org/3/movie/popular?api_key=475ade4409e1a8eaf37a2b07efab15ef";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_download);
   /* public static void verifyStoragePermissions(Download download) {
        // Check if we have write permission
        int permission = ActivityCompat.checkSelfPermission(download, Manifest.permission.WRITE_EXTERNAL_STORAGE);

        if (permission != PackageManager.PERMISSION_GRANTED) {
            // We don't have permission so prompt the user
            ActivityCompat.requestPermissions(
                    download,
                    PERMISSIONS_STORAGE,
                    REQUEST_EXTERNAL_STORAGE
            );
        }*/
    Rvdown = findViewById(R.id.Rv_download);
    DownmovieImg = findViewById(R.id.img_download);
    Down_tv_title = findViewById(R.id.down_title);
    Down_tv_summary = findViewById(R.id.down_summary);
//    iniSetUpRvDown();

GetData getData= new GetData();
getData.execute();



}





/*private void iniSetUpRvDown() {
    DownAdapter downAdapter = new DownAdapter(this, DataSource.getDown());
    Rvdown.setAdapter(downAdapter);
    Rvdown.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
}*/


@SuppressLint("StaticFieldLeak")
public class GetData extends AsyncTask<String,String,String> {

    @Override
    protected String doInBackground(String... strings) {
        String current = "";
        HttpURLConnection urlConnection = null;
        try {
            URL url;
            urlConnection = null;
            url = new URL(JSON_URL);
            urlConnection = (HttpURLConnection) url.openConnection();
            InputStream is = urlConnection.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            int data = isr.read();
            while (isr.read() != -1) {
                data = isr.read();
                current += (char) data;
            }
            return current;
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
        } finally {
            if (urlConnection != null) ;
            urlConnection.disconnect();
        }



        return current;
    }

    @Override
    protected void onPostExecute(String results) {
        try {
            JSONObject jsonObject= new JSONObject(results);
            JSONArray jsonArray=jsonObject.getJSONArray("results");
            for (int i=0;i<jsonArray.length();i++){
                JSONObject jsonObject1 =  jsonObject.getJSONObject(String.valueOf(i));
                Test model = new Test();

                //model.setPoster_path(jsonObject1.getInt("poster_path"));
                model.setOriginal_language(jsonObject1.getString("original_language"));
                model.setOriginal_title(jsonObject1.getString("original_title"));
                testList.add(model);

            }
        } catch (JSONException e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
        }
       putDataintoRecyclerview(testList);

    }
}



private void putDataintoRecyclerview(List<Test>testList) {
    testList= new ArrayList<>();
    DownAdapter downAdapter = new DownAdapter(this, testList);
    Rvdown.setLayoutManager(new LinearLayoutManager(this));
    Rvdown.setAdapter(downAdapter);

}

}

'I am trying to fetch data from an API, but keep getting this error : 1-java.lang.reflect.InvocationTargetException 2-android.system.ErrnoException: open failed: EACCES (Permission denied)'

  • https://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-android – z.g.y Nov 07 '22 at 06:37
  • can you help me with "org.json.JSONException: Value pg"1"eut" of type java.lang.String cannot be converted to JSONObject" – Saloni Tyagi Nov 07 '22 at 06:48

0 Answers0