Issue Detected at a Precise Line Number - Android Studio

Despite my numerous attempts to modify the specific line in question, including leaving it empty, turning it into a comment, or removing it entirely, the error message persists. I even went as far as deleting the class and creating a new one, but the same line continues to be flagged as the issue.

The problematic code line (109) is highlighted below:

package com.example.president;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Game extends AppCompatActivity implements View.OnClickListener {


    private Manager gManager;
    Player p1,p2,p3;
    private ImageView[] hand;
    private ImageView[] curr;
    private ImageView[] next= new ImageView[3];
    private int[] turn = {0, 1, 2};
    private int cthrow;
    public int[] cards =
            {
                    R.drawable.c3,
                    R.drawable.c4,
                    R.drawable.c5,
                    // Remaining card images truncated for brevity...
                    
                    R.drawable.d11,
                    R.drawable.d12,
                    R.drawable.d13,
                    R.drawable.d1,
                    R.drawable.d2,
                    R.drawable.j1,
                    R.drawable.j2
            };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game);

        p1 = new Player("p1");
        p2 = new Player("p2");
        p3 = new Player("p3");

        this.hand = new ImageView[18];
        String str;
        int resId;
        int i;
        for (i=0;i<hand.length;i++)
        {
            str = "card"+i;
            resId = getResources().getIdentifier(str, "id", getPackageName());
            hand[i]= (ImageView)findViewById(resId);
            hand[i].setOnClickListener(this);
        }
        for (i=0; i<4; i++)
        {
            str="board"+i;
            resId = getResources().getIdentifier(str, "id", getPackageName());
            curr[i]= (ImageView)findViewById(resId);
            curr[i].setOnClickListener(this);
        }

        this.gManager = new Manager(this, p1, p2, p3);

        this.gManager.handingDeck(p1, p2, p3);
[[[LINE 109]]]
        startGame(p1, p2, p3);

    }

    public void startGame(Player p1, Player p2, Player p3) {

        Player p=p1;
        int i;
        for (i=0; i < 18; i++) {
            hand[i].setImageResource(cards[p.getHand().get(i).getIndex()]);
        }
        String text = p1.getHand().toString();
        TextView change = (TextView)findViewById(R.id.textView);
        change.setText(text);
    }

    @Override
    public void onClick(View v) {
        int i, cnum=0, t=0, resId;
        boolean found = false;
        Player p=p1;
        cthrow=1;
        for (i = 0; i < 18 && (!(found)); i++)
        {
            if (v.getId() == hand[i].getId())
            {
                String str="card"+cnum;
                resId=getResources().getIdentifier(str, "id", getPackageName());
                next[turn[t]]= (ImageView)findViewById(resId);
                found=true;
                curr[cthrow].setImageResource(cards[p.getHand().get(i).getIndex()]);
                p.getHand().remove(i);
                next[turn[t]].setVisibility(View.INVISIBLE);
                if(cnum<10)
                    cnum=18-cnum;
                else
                    cnum=18-cnum+1;
                cthrow++;
            }
        }
    }
}

Even with an empty line at that position, the error persists.

https://i.sstatic.net/7Wijh.png

Answer №1

It has been brought to attention in the comments that the error actually occurs at this point:

HERE>> curr[i]= (ImageView)findViewById(resId);
curr[i].setOnClickListener(this);

The error will be present on any line where you use curr as it has not been initialized.

In relation to your specific error: If an error persists even after intentionally changing your code, there is only one likely explanation: the currently running code is an old version. To resolve this issue, consider refreshing it. Here are some steps you can follow incrementally (testing for changes along the way):

  • Rebuild your project (using the rebuild button in your IDE or through the command line)
  • Perform a clean build of your project (through the IDE or command line as mentioned above)
  • Redeploy your application (for Android applications, 're-install' it on the device you are testing it on - emulator or phone)
  • Uninstall and delete the current application running (then repeat steps 2 & 3)
  • Restart your test device (emulator/phone) and repeat steps 2 & 3
  • Restart your IDE (if unsure if all processes have rebooted, restart your PC)
  • Delete any build intermediate/cache files stored by your IDE and then repeat steps 2 & 3
  • If nothing has worked, try different combinations of the solutions mentioned above
  • If none of the above solutions work, start considering basic factors and think creatively:
    • Am I installing the app correctly?
    • Have I saved the modified files?
    • Is the phone properly connected?
    • Am I modifying the files in the correct project?
    • ...

I hope this guidance proves helpful to you.

Answer №2

There was an error in the way you initialized the array. By using new, it will properly initialize the array and allocate memory for it.

-- So, the correct way to initialize and add values to the array is as follows:

public int[] cards = new int[]{ add your integers here };

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When transferring the code to an exported function, it triggers a TypeError indicating a circular structure conversion issue when trying to convert

Experimenting with queries using the express and mysql packages, I encountered an issue when moving code to a different file for exporting. Initially, this code snippet worked without any problems: connection.connect(); connection.query('SELECT 1 + ...

how to pass arguments to module.exports in a Node.js application

I have created a code snippet to implement a Node.js REST API. app.js var connection = require('./database_connector'); connection.initalized(); // I need to pass the connection variable to the model var person_model = require('./mod ...

How to print a specific div from an HTML page with custom dimensions

I am looking for a solution to print just a specific div from a website with dimensions of 3"x5". Despite setting up the print button, the entire page continues to print every time. Is there a way to hide all non-div content in print preview? CSS .wholeb ...

The upload directory fails to include the folder name when sending a file

After experimenting with the new directory upload feature, I encountered an issue where the server request did not preserve the exact folder structure as expected. Here is the HTML code snippet: <form action="http://localhost:3000/" method="post" enct ...

Renewed Promises: Exploring Promises in Angular JS

Revised with HTTP and initial code inspired by requests/Refer to the end of the post: Lately, I have been seeking help from the amazing SO community as I navigate through my AngularJS learning journey. I used to be a traditional C programmer but recently ...

Tips for tailoring content based on screen size

I am looking for a way to display different content depending on whether the user is viewing my website on a large screen (PC/tablet) or a small screen (mobile). While my site is responsive and uses bootstrap, I have a lot of content that is only suitable ...

Retrieving the text content from a JSON key

I have the following JSON data saved in a jQuery variable called "jsondata": var jsondata = { "Name": { "Jaken": {}, "Test": {}, "Hello": {} }, "Date": { "Today": {}, "Tomorrow": {}, "Wednesday": {} }, "Description": { ...

Galaxy S3 JSON Parsing Problem

I have been developing a small application that retrieves the current geographical coordinates and returns the corresponding address using json objects. I have encountered an issue where the app works perfectly on Samsung Galaxy S, but encounters a runtime ...

The ajax keypress event is malfunctioning and the ActionResult parameter is failing to capture any data

I am facing an issue where I want to update the value of a textbox using AJAX on keypress event, but the controller is not receiving any value to perform the calculation (it's receiving null). <script> $('#TotDiscnt').keypress(fu ...

Fancybox fails to acknowledge the thumbs feature

I received a sneak peek of five thumbnails for a gallery, but the actual gallery contains even more photos. To prevent cluttering my code, I decided to store them in an array. Here is the snippet of HTML code: <div id="start_slides"> <a href ...

Displaying a notification for a multi-selection using JavaScript

I need help with a piece of Html code I have. It's a list of countries, and what I want is to show an alert when one or more countries are selected to display which ones were chosen. I'm working with JavaScript only and don't want to use Jqu ...

Placing a user's username within an ejs template using express and node.js

Currently, I am attempting to integrate the username into a layout using ejs templating with node and express. Below are the steps I have taken: Mongodb model: const mongoose = require('mongoose') const Schema = mongoose.Schema; var uniqueValid ...

Error: Unable to access the 'style' property of null in prac.js at line 3

const heading = document.querySelector("h1"); heading.style.color = "blue"; Encountering an error when attempting to apply color to h1 element using DOM manipulation within a separate JavaScript file. The 2-line code snippet works flawlessly in the consol ...

Utilize ramda.js to pair an identifier key with values from a nested array of objects

I am currently working on a task that involves manipulating an array of nested objects and arrays to calculate a total score for each identifier and store it in a new object. The JSON data I have is structured as follows: { "AllData" : [ { "c ...

Ways to create auto-suggest recommendations that exceed the boundaries of the dialogue container

Is there a way to position autosuggest suggestions above the dialog instead of within it, in order to prevent scrolling of dialog content? Check out this sandbox example for reference: https://codesandbox.io/embed/adoring-bogdan-pkou8https://i.sstatic.net ...

jQuery Ajax comes with a built-in method for validating serialized forms. This method allows

After creating a form and serializing it to send to my MVC Action method, here is how my jQuery Ajax script looks: $('#submit').click(function () { var jsonObj = $('#form').serialize(); alert(jsonObj); $.ajax({ ty ...

Dealing with Superagent and Fetch promises - Tips for managing them

Apologies for posing a question that may be simple for more seasoned JS programmers. I've been delving into superagent and fetch to make REST calls, as I successfully implemented odata but now need REST functionality. However, I'm facing confusio ...

How can I dynamically insert a variable string into a link tag using React and TypeScript?

I am just starting out with javascript and typescript, and I need to generate a link based on certain variables. I am currently facing an issue trying to insert that link into <a href="Some Link"> Some Text </a> Both the "Some Text" and "Som ...

Switching between nested lists with a button: A simple guide

I have successfully created a nested list with buttons added to each parent <li> element. Here is how the list is structured: $("#pr1").append("<button id='bnt-cat13' class='buttons-filter'>expnd1</button>"); $("#pr ...

jQuery validation does not work properly when using .element(element) in a custom method

I am struggling with a custom rule that is supposed to check dependencies by validating other inputs it relies on. However, when I implement this validation, it seems like all other validations are being ignored. Here is my custom validation rule: jQuery ...