0

I am trying to make a program for my class that makes an matrix of integers and then add the numbers from the 4th row. Here is the code

    import java.util.Scanner;
    import java.awt.Font;
    import java.awt.GridLayout;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.*;
    import java.awt.*;

    public class Warmup
    {
    public static void main(String[] args)
    {

        int[][] warmups = new int[5][7];

  for(int r = 0;r<warmups.length;r++){
     for(int c = 0;c<warmups.length;c++)
        warmups[r][c]=(int)(Math.random()*6+2);}

  int answer = 0;
for (int c = 0; c < warmups[4].length; c++)
  answer += Integer.parseInt(warmups[4][c].getText()); //error

System.out.println(answer);

  }

  }
  • Heya mate, you should post what your question is, the stack trace of the error, and fix the formatting of your code to make the indenting consistent. – Tim Hunter Apr 17 '20 at 19:36
  • 1
    Hey! An `int` is a primitive data structure; it doesn't have methods because it doesn't reference an object. You cannot *dereference* what is not a reference but this is what you're trying when you call a method on it. – akuzminykh Apr 17 '20 at 19:37
  • The error message is telling you exactly what is wrong -- you're trying to call a method on a primitive and that is not valid Java. If you want to convert an int to a String, there are legal ways to do it, including the kludge `String s = "" + myInt;` or `Integer.toString(...)` which are you already calling. – Hovercraft Full Of Eels Apr 17 '20 at 19:39

0 Answers0