Reputation: 13
So my main error is in the ScoreDisplay.java
public class ScoreDisplay extends AppCompatActivity { int score;
score= getIntent().getIntExtra("score",0);
}
int score is fine but in the next line it says - unknown class score -invalid method declaration; return type required - missing method body, or declare abstract - parameter expected
and yea so everything is red in my java class and where do i put my textview.textview show ect. that you told me?
Upvotes: 0
Views: 100
Reputation: 12803
Change
if (mQuestionNumber < mQuestionLibrary.getQuestionCount())
updateQuestion();
else
//Show next screen
setContentView(R.layout.scoredisplay);
to
if (mQuestionNumber < mQuestionLibrary.getQuestionCount())
updateQuestion();
else
{
Intent intent = new Intent(QuizActivity.this,ScoreDisplay.class);
intent.putExtra("score",mScore);
startActivity(intent);
}
Create a new jave called ScoreDisplay, and receive the mScore
value from QuizActivity to ScoreDisplay by using this
int score;
score= getIntent().getIntExtra("score",0);
Finally display the score to your textView
.
textview.setText(score+"");
ScoreDisplay.java
public class ScoreDisplay extends AppCompatActivity {
TextView myScore;
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scoredisplay);
score= getIntent().getIntExtra("score",0);
myScore = (TextView)findViewById(R.id.endingScore);
myScore.setText(score+"");
}
}
Add below code to your mainfest to solve crash problem.
<activity android:name=".ScoreDisplay"></activity>
AndroidMainfest FullCode
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mgilani.co.multipleqa">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".QuizActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ScoreDisplay"></activity> //new line
</application>
</manifest>
Upvotes: 0