Aaron Kauffman
Aaron Kauffman

Reputation: 163

Android Studio 'class' or 'interface' expected

I've written some code in Java for creating random sentences. It works on an online Java Compiler, although I can't seemed to get it running on Android Studio. Here's my code:

package com.tech.littlest.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Random;

public class Activity2 extends AppCompatActivity {
    final static int NO_DEDICATED_ARRAYS = 12;  // This number is equal to the number of arrays in a string NOTE: This number MUST be constant across all strings
    final static int NO_OUTPUT_SENTENCES = 1;   // How many sentences generated and displayed for the user
    final static String SPACER = " ";   // Inputs a " " character (Space) into the display
    final static String PERIOD = ".";
    static Random r = new Random();
    public static void main( String args[] ){
        String proposition_user[] = { "You should build and invention that", "You should build a robot that", "You should create a whatchamacallit that", "There should be a device that", "Create a futuristic thing that", "Make a thing that", "Make something cool that", "I don't recall there being a thing that", "Create a sick thing that", "Devise a plan to create an object that", "I want a thing that", "If I just had an thingamajig that", "Create a thingimajig that"};
        String plural_noun[] = { "children", "chickens", "the ocean", "cars", "apples", "houses", "water", "buildings", "people", "your friends", "farms", "the human race" };
        String verb[] = { "directs you to", "drives on", "manages", "develops", "makes","eats", "helps", "relocates", "fixes", "feeds", "runs on", "washes" };
        String sentence;
        for (int i = 0; i < NO_OUTPUT_SENTENCES; i++){
            sentence = proposition_user[rand()];
            char c = sentence.charAt(0);
            sentence = sentence.replace( c, Character.toUpperCase(c) );
            sentence += SPACER;
            sentence += (verb[rand()]);
            sentence += (SPACER + plural_noun[rand()]);
            sentence += PERIOD;
            sentence += "";
            System.out.println(sentence);
        }
    }
    static int rand(){
        int ri = r.nextInt() % NO_DEDICATED_ARRAYS;
        if ( ri < 0 )
            ri += NO_DEDICATED_ARRAYS;
        return ri;
    }

}


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

I get a 'class' or 'interface' expected error at line 37. The third to last bracket. Thank you.

Upvotes: 0

Views: 1258

Answers (2)

Nico_ptrs
Nico_ptrs

Reputation: 1

Remove the } at line 37.

It closes the public class Activity2 extends AppCompatActivity { (line 7) while you still have code below it.

Upvotes: 0

regev avraham
regev avraham

Reputation: 1112

You should remove that extra } you have after the static int rand() function

Upvotes: 3

Related Questions