karkatsanger
Lurker
Like the title says, the symbol 'R' cannot be resolved. I am using android studio.
The code:
My xml looks like this:
So I just rewrote the entire thing, cause it was basically just the main class and a little bit more, and now there are no errors.
The code:
Java:
package me.karkatsanger.insertname;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
private Button button2;
private void init() {
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent mail = new Intent(MainActivity.this, Mail.class);
startActivity(mail);
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
init();
}
public void preform_action(View v) {
Random rand = new Random();
int minNumber = 1;
int maxNumber = 10;
int randomNumber = rand.nextInt((maxNumber - minNumber) + minNumber) + minNumber;
TextView tv = (TextView) findViewById(R.id.facts);
if (randomNumber == 1) {
tv.setText("Number One");
}else if (randomNumber == 2) {
tv.setText("Number Two");
}else if (randomNumber == 3) {
tv.setText("Number Three");
}else if (randomNumber == 4) {
tv.setText("Number Four");
}else if (randomNumber == 5) {
tv.setText("Number Five");
}else if (randomNumber == 6) {
tv.setText("Number Six");
}else if (randomNumber == 7) {
tv.setText("Number Seven");
}else if (randomNumber == 8) {
tv.setText("Number Eight");
}else if (randomNumber == 9) {
tv.setText("Number Nine");
}else {
tv.setText("Number Ten");
}
}
}
My xml looks like this:
Java:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.karkatsanger.insertname.MainActivity"
android:background="@drawable/ohh">
<Button
android:id="@+id/factsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap me for facts"
android:background="#"
android:textColor="#F20"
android:onClick="preform_action"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#"
android:textColor="#F20"
android:text="Any other quesitons?"
tools:layout_editor_absoluteX="98dp"
tools:layout_editor_absoluteY="447dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/facts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp"
android:textColor="#F20"
tools:layout_editor_absoluteY="247dp"
tools:layout_editor_absoluteX="163dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
So I just rewrote the entire thing, cause it was basically just the main class and a little bit more, and now there are no errors.
Last edited: