1

I am beginner programmer and I am trying to create my own Sudoku Generator using existing code that i found here http://ostermiller.org/qqwing/QQWing.java.html I put it in separate file in my package.

I don't know exactly how to do this. I tried to fill my board with proper Sudoku numbers, but it only fills in zeros. Here is my code:

QQWing wing = new QQWing();

        try {
            wing.generatePuzzle();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



      // Create the layout
      TableLayout table = new TableLayout(this);


      TableLayout.LayoutParams lp = new TableLayout.LayoutParams(
              ViewGroup.LayoutParams.FILL_PARENT,
              ViewGroup.LayoutParams.FILL_PARENT);

              table.setLayoutParams(lp); // This line has no effect! WHYYYY?!
              table.setStretchAllColumns(true);
              EditText editText[][] = new EditText[9][9];
              for (int i = 0; i < 9; ++i)
              {
              TableRow row = new TableRow(this);
              for (int j = 0; j < 9; ++j)
              {
                  editText[i][j] = new EditText(this);

                    editText[i][j].setText(String.valueOf(wing.puzzle[i*9+j]));
                    editText[i][j].setWidth(50);
                    row.addView(editText[i][j]);
              }
              table.addView(row);
              }
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Piotr Suchanek
  • 374
  • 1
  • 6
  • 20

2 Answers2

1

This is Stephen Ostermiller, the author of QQWing.

I'm happy to report that this issue has been fixed in QQWing version 1.3.3. The Java API has been improved quite a bit:

  • Exception is no longer thrown
  • The random number generator is initialized automatically
  • It has been placed in the com.qqwing package

Here is Test.java that uses QQWing:

import com.qqwing.*;

public class Test {
    public static void main(String[] args){
        QQWing qq = new QQWing();
        qq.generatePuzzle();
        System.out.println(qq.getPuzzleString());
    }
}

It can be compiled and run like this:

$ javac -classpath qqwing-1.3.3.jar Test.java && java -classpath .:qqwing-1.3.3.jar Test
 . . 5 | 8 . . | 3 4 .
 . . 6 | . 7 . | . 2 1
 3 . 8 | 2 . . | . . .
-------|-------|-------
 . . . | 4 6 5 | . 1 .
 . . . | . . . | . . .
 . 7 . | 1 3 . | 6 8 .
-------|-------|-------
 . . . | . . . | 1 3 .
 . . 4 | . . . | 2 . .
 . . . | . . . | . 5 6

The latest version of QQWing can be downloaded from the QQWing website.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
0

Its because you catching all exceptions and you should avoid that. generatePuzzle() throws NPE as the Random r is null because the source is badly written and cant be userd just by instantiating QQWing.

Use it like this for start:

QQWing.r = new Random();
QQWing wing = new QQWing();
Lubos Horacek
  • 1,562
  • 10
  • 28