Hi.
My name is Roly32. I'm creating this thread because I'm having some problems with AndroidStudio 1.2 developing. I'm using "The Big Nerd Ranch Guide 2nd Edition", and AndroidStudio 1.2, so I can't have problems with version compatibility.
The book recommend to develop an App with him, "GeoQuiz" (a geographic quiz). It gives codes, and I write it. But when I need to run, to test the app.. Errors.
QuizActivity.java
package com.bignerdranch.android.geoquiz;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
public class QuizActivity extends AppCompatActivity {
private Button mTrueButton ButtonfindViewById(R.id.true_button);
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mTrueButton = (Button) findViewById(R.id.true_button);
@override
public void onClick (View v){
Toast.makeText(QuizActivity.this,
R.string.incorrect_toast,
Toast.LENGTH_SHORT).show();
}
});
mFalseButton = (Button) findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
R.string.correct_toast,
Toast.LENGTH_SHORT).show();
}
}
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
ActivityQuiz.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android
rientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android
adding="24dp"
android:text="@String/question_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android
rientation="horizontal" >
<Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@String/true_button" />
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@String/false_button" />
</LinearLayout>
strings.xml
GeoQuiz
<string name="question_text">Constantinople is the largest city in Turkey!</string>
<string name="true_button">True</string>
<string name="false_button">False</string>
<string name="correct_toast">Correct!</string>
<string name="incorrect_toast">Incorrect!</string>
<string name="action_settings">Settings</string>
Errors:
Error
10, 31) error: ';' expected
Error
10, 32) error: invalid method declaration; return type required
Error
10, 67) error: expected
Error
18, 28) error: ';' expected
Error
18, 36) error: ';' expected
Error
23, 6) error: illegal start of type
Error
24, 25) error: expected
Error
25, 36) error: expected
Error
25, 37) error: illegal start of type
Error
25, 40) error: ')' expected
Error
25, 45) error: ';' expected
Error
25, 46) error: invalid method declaration; return type required
Error
27, 28) error: ';' expected
Error
27, 35) error: ';' expected
Error
28, 21) error: not a statement
Error
28, 35) error: ';' expected
Error
29, 26) error: not a statement
Error
29, 39) error: ';' expected
Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
(All errors are referred to QuizActivity.java.) I don't know what to do, now. I copied the text exactly from the book, but nothing..
My name is Roly32. I'm creating this thread because I'm having some problems with AndroidStudio 1.2 developing. I'm using "The Big Nerd Ranch Guide 2nd Edition", and AndroidStudio 1.2, so I can't have problems with version compatibility.
The book recommend to develop an App with him, "GeoQuiz" (a geographic quiz). It gives codes, and I write it. But when I need to run, to test the app.. Errors.
QuizActivity.java
package com.bignerdranch.android.geoquiz;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
public class QuizActivity extends AppCompatActivity {
private Button mTrueButton ButtonfindViewById(R.id.true_button);
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mTrueButton = (Button) findViewById(R.id.true_button);
@override
public void onClick (View v){
Toast.makeText(QuizActivity.this,
R.string.incorrect_toast,
Toast.LENGTH_SHORT).show();
}
});
mFalseButton = (Button) findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
R.string.correct_toast,
Toast.LENGTH_SHORT).show();
}
}
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
ActivityQuiz.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android
rientation="vertical" ><TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android
adding="24dp"android:text="@String/question_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android
rientation="horizontal" ><Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@String/true_button" />
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@String/false_button" />
</LinearLayout>
strings.xml
GeoQuiz
<string name="question_text">Constantinople is the largest city in Turkey!</string>
<string name="true_button">True</string>
<string name="false_button">False</string>
<string name="correct_toast">Correct!</string>
<string name="incorrect_toast">Incorrect!</string>
<string name="action_settings">Settings</string>
Errors:
Error
10, 31) error: ';' expectedError
10, 32) error: invalid method declaration; return type requiredError
10, 67) error: expectedError
18, 28) error: ';' expectedError
18, 36) error: ';' expectedError
23, 6) error: illegal start of typeError
24, 25) error: expectedError
25, 36) error: expectedError
25, 37) error: illegal start of typeError
25, 40) error: ')' expectedError
25, 45) error: ';' expectedError
25, 46) error: invalid method declaration; return type requiredError
27, 28) error: ';' expectedError
27, 35) error: ';' expectedError
28, 21) error: not a statementError
28, 35) error: ';' expectedError
29, 26) error: not a statementError
29, 39) error: ';' expectedError:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
(All errors are referred to QuizActivity.java.) I don't know what to do, now. I copied the text exactly from the book, but nothing..