Create Android Quiz App with MySQL JSON Parsing and PHP

I have been testing my programming skills recently. So I was trying to study android by creating some simple applications by using Android studio. So, In this post i will share the code for creating an android quiz app. with this app, the user can select one answer from the four options available. The score of the quiz is also displayed at the end of the quiz.

Requirements for Creating Android Quiz app

  • Computer with Android studio Installed
  • Basic Knowledge about Android studio
  • MySQL database (if you dont have a MySQL database, click here to learn more about free MySQL database)

About the Application

First of all. I will tell you what we are trying to achieve to give a basic idea about what we are about to create. In the Home screen you can see a button called start quiz. Now you will be redirected to a screen with a question and four options. user can select one option from the group and click submit. Now it will show the right answer in Green color text. Then, user can click next to go to next question. After completing the quiz, The score is displayed.

android quiz app with scorecreate android free quiz app android studio


Setting up MySQL server for  Android app

First, we have to setup MySQL database for storing questions and answers. Open phpmyadmin and create a database. Inside the database, create a table called quiz_questions with 4 fields. The details of the fields inside the table are given below.

android mysql json php quiz app


Enter some data to the table by using phpmyadmin. ID will be auto incremented. In the possible_answers field, Enter the options seperated by comma. In the correct answer field, enter which is the correct answer. if the third option is the correct answer, Enter the correct_answer field as 3.
Now copy the below code and paste in a notepad file. change the host, user,password and database name and save it as quiz.php .
<?php
$host="Your host name here";
$username="Your user name here";
$password="Your password here";
$db_name="Your database name here";
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "select * from quiz_questions ORDER BY RAND() LIMIT 10";
$result = mysql_query($sql);
$json = array();
if(mysql_num_rows($result)){
while($row=mysql_fetch_assoc($result)){
$json['quiz_questions'][]=$row;
}
}
mysql_close($con);
echo json_encode($json);
?>
view raw quiz.php hosted with ❤ by GitHub

Now upload this file to the root of your MySQL server by using file manager in your cpanel or by using FTP. Now try accessing the file by using,
http://yoursiteurl.com/quiz.php. If it is showing the data of your table successfully. Save the Url as we need it in future. Proceed with the below steps.

How to create Android quiz app

update (15/09/2017) : The apache http library is depreciated. So you have to add this compile statement in your App level build.gradle file(under dependencies)

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
  • First of all. create a new project in Android Studio. Enter all the details. Select Blank activity, On next screen click finish
  • In the activity_main.xml, paste the below code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="Start Quiz"
android:layout_alignParentTop="true"
android:layout_marginTop="92dp"
/>
</RelativeLayout>


In the MainActivity.java, Paste the below code
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button startButton = (Button)findViewById(R.id.button);
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
if(isNetworkStatusAvialable (getApplicationContext())) {
startActivity(intent);
}
else {
Toast.makeText(getApplicationContext(), "Internet not available", 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);
}
public void onBackPressed() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this);
// set title
alertDialogBuilder.setTitle("Exit");
/// set dialog message
alertDialogBuilder
.setMessage("Do you really want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory( Intent.CATEGORY_HOME );
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
public static boolean isNetworkStatusAvialable (Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null)
{
NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
if(netInfos != null)
if(netInfos.isConnected())
return true;
}
return false;
}
}


Now create a new activity by right clicking on App and select New>>Activity>>Blank Activity
Name it as QuizActivity. In the activity_quiz.xml, paste below code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="androidquizapplication.QuizActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question"
android:id="@+id/quiz_question"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textColor="#000000"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="@+id/radioGroup" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/quiz_question"
android:layout_alignStart="@+id/quiz_question">
<RadioButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/radio0"
android:textSize="15sp"
android:text="@string/app_name"
android:layout_marginBottom="10dp"
android:paddingLeft="20dp"/>
<RadioButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/radio1"
android:textSize="15sp"
android:text="@string/app_name"
android:layout_marginBottom="10dp"
android:paddingLeft="20dp"/>
<RadioButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/radio2"
android:textSize="15sp"
android:text="@string/app_name"
android:layout_marginBottom="10dp"
android:paddingLeft="20dp"/>
<RadioButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/radio3"
android:textSize="15sp"
android:text="@string/app_name"
android:paddingLeft="20dp"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultView"
android:layout_below="@+id/radioGroup"
android:layout_alignLeft="@+id/radioGroup"
android:layout_alignStart="@+id/radioGroup" />
<Button
android:layout_height="wrap_content"
android:layout_width="160dp"
android:gravity="center"
android:id="@+id/nextquiz"
android:text="Submit"
android:padding="5dp"
android:layout_alignTop="@+id/previousquiz"
android:layout_alignRight="@+id/quiz_question"
android:layout_alignEnd="@+id/quiz_question"/>
<Button
android:layout_height="wrap_content"
android:layout_width="160dp"
android:gravity="center"
android:textColor="#ffffff"
android:id="@+id/previousquiz"
android:background="@drawable/quizbutton"
android:text="@string/previous_questions"
android:padding="5dp"
android:layout_below="@+id/resultView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>


In the QuizActivity.java, Paste below code

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class QuizActivity extends ActionBarActivity {
private TextView quizQuestion;
private TextView result;
private RadioGroup radioGroup;
private RadioButton optionOne;
private RadioButton optionTwo;
private RadioButton optionThree;
private RadioButton optionFour;
private int currentQuizQuestion;
private int quizCount;
private QuizWrapper firstQuestion;
private List<QuizWrapper> parsedObject;
public int correctAnswerForQuestion;
public int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
quizQuestion = (TextView) findViewById(R.id.quiz_question);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
optionOne = (RadioButton) findViewById(R.id.radio0);
optionTwo = (RadioButton) findViewById(R.id.radio1);
optionThree = (RadioButton) findViewById(R.id.radio2);
optionFour = (RadioButton) findViewById(R.id.radio3);
final Button previousButton = (Button) findViewById(R.id.previousquiz);
Button nextButton = (Button) findViewById(R.id.nextquiz);
result = (TextView) findViewById(R.id.resultView);
AsyncJsonObject asyncObject = new AsyncJsonObject();
asyncObject.execute("");
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
result.setText(" ");
if (currentQuizQuestion >= quizCount) {
final Intent intent = new Intent(QuizActivity.this, complete.class);
startActivity(intent);
return;
} else {
previousButton.setVisibility(Button.VISIBLE);
optionOne.setTextColor(Color.BLACK);
optionTwo.setTextColor(Color.BLACK);
optionThree.setTextColor(Color.BLACK);
optionFour.setTextColor(Color.BLACK);
firstQuestion = parsedObject.get(currentQuizQuestion);
quizQuestion.setText(firstQuestion.getQuestion());
String[] possibleAnswers = firstQuestion.getAnswers().split(",");
uncheckedRadioButton();
optionOne.setText(possibleAnswers[0]);
optionTwo.setText(possibleAnswers[1]);
optionThree.setText(possibleAnswers[2]);
optionFour.setText(possibleAnswers[3]);
}
}
});
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
previousButton.setVisibility(Button.INVISIBLE);
int radioSelected = radioGroup.getCheckedRadioButtonId();
int userSelection = getSelectedAnswer(radioSelected);
correctAnswerForQuestion = firstQuestion.getCorrectAnswer();
if (userSelection == correctAnswerForQuestion) {
// correct answer
if (correctAnswerForQuestion==1)
{
optionOne.setTextColor(getResources().getColor(R.color.green));
}
else if (correctAnswerForQuestion==2)
{
optionTwo.setTextColor(getResources().getColor(R.color.green));
}
else if (correctAnswerForQuestion==3)
{
optionThree.setTextColor(getResources().getColor(R.color.green));
}
else if (correctAnswerForQuestion==4)
{
optionFour.setTextColor(getResources().getColor(R.color.green));
}
score=score+1;
currentQuizQuestion++;
} else {
// failed question
result.setTextColor(Color.parseColor("#FF0000"));
if (correctAnswerForQuestion==1)
{
optionOne.setTextColor(getResources().getColor(R.color.green));
}
else if (correctAnswerForQuestion==2)
{
optionTwo.setTextColor(getResources().getColor(R.color.green));
}
else if (correctAnswerForQuestion==3)
{
optionThree.setTextColor(getResources().getColor(R.color.green));
}
else if (correctAnswerForQuestion==4)
{
optionFour.setTextColor(getResources().getColor(R.color.green));
}
currentQuizQuestion++;
return;
}
}
});
}
@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_quiz, 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);
}
private class AsyncJsonObject extends AsyncTask<String, Void, String> {
private ProgressDialog progressDialog;
@Override
protected String doInBackground(String... params) {
HttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httpPost = new HttpPost("http://yoursite.com/quiz.php");
String jsonResult = "";
try {
HttpResponse response = httpClient.execute(httpPost);
jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
System.out.println("Returned Json object " + jsonResult.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonResult;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progressDialog = ProgressDialog.show(QuizActivity.this, "Loading Quiz", "Please Wait....", true);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progressDialog.dismiss();
System.out.println("Resulted Value: " + result);
parsedObject = returnParsedJsonObject(result);
if (parsedObject == null) {
return;
}
quizCount = parsedObject.size();
firstQuestion = parsedObject.get(0);
quizQuestion.setText(firstQuestion.getQuestion());
String[] possibleAnswers = firstQuestion.getAnswers().split(",");
optionOne.setText(possibleAnswers[0]);
optionTwo.setText(possibleAnswers[1]);
optionThree.setText(possibleAnswers[2]);
optionFour.setText(possibleAnswers[3]);
}
private StringBuilder inputStreamToString(InputStream is) {
String rLine = "";
StringBuilder answer = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
while ((rLine = br.readLine()) != null) {
answer.append(rLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return answer;
}
}
private List<QuizWrapper> returnParsedJsonObject(String result) {
List<QuizWrapper> jsonObject = new ArrayList<QuizWrapper>();
JSONObject resultObject = null;
JSONArray jsonArray = null;
QuizWrapper newItemObject = null;
try {
resultObject = new JSONObject(result);
System.out.println("Testing the water " + resultObject.toString());
jsonArray = resultObject.optJSONArray("quiz_questions");
} catch (JSONException e) {
e.printStackTrace();
}
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonChildNode = null;
try {
jsonChildNode = jsonArray.getJSONObject(i);
int id = jsonChildNode.getInt("id");
String question = jsonChildNode.getString("question");
String answerOptions = jsonChildNode.getString("possible_answers");
int correctAnswer = jsonChildNode.getInt("correct_answer");
newItemObject = new QuizWrapper(id, question, answerOptions, correctAnswer);
jsonObject.add(newItemObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
return jsonObject;
}
private int getSelectedAnswer(int radioSelected) {
int answerSelected = 0;
if (radioSelected == R.id.radio0) {
answerSelected = 1;
}
if (radioSelected == R.id.radio1) {
answerSelected = 2;
}
if (radioSelected == R.id.radio2) {
answerSelected = 3;
}
if (radioSelected == R.id.radio3) {
answerSelected = 4;
}
return answerSelected;
}
private void uncheckedRadioButton() {
optionOne.setChecked(false);
optionTwo.setChecked(false);
optionThree.setChecked(false);
optionFour.setChecked(false);
radioGroup.clearCheck();
}
public class QuizWrapper {
private int id;
private String question;
private String answers;
private int correctAnswer;
public QuizWrapper(int id, String question, String answers, int correctAnswer) {
this.id = id;
this.question = question;
this.answers = answers;
this.correctAnswer = correctAnswer;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnswers() {
return answers;
}
public void setAnswers(String answers) {
this.answers = answers;
}
public int getCorrectAnswer() {
return correctAnswer;
}
public void setCorrectAnswer(int correctAnswer) {
this.correctAnswer = correctAnswer;
}
}
}
In line number 185, you can see a space for a url. Paste the url for the MySQL server you created earlier. it will be like http://yoursite.com/quiz.php
Now Create another activitylike above and name it as complete
Paste the below code in activity_complete.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="app.quiz.com.quiz2016.complete">
<TextView android:text="Quiz Complete" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/restart"
android:layout_alignLeft="@+id/restart"
android:layout_alignStart="@+id/restart"
android:layout_marginBottom="85dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/restart"
android:text="PLAY AGAIN"
android:onClick="restartQuiz"
android:layout_above="@+id/mainmenu"
android:layout_alignLeft="@+id/mainmenu"
android:layout_alignStart="@+id/mainmenu" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainmenu"
android:text="Main Menu"
android:onClick="mainMenu"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>


Now in the complete.java, Paste the below code
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class complete extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complete);
int score = getIntent().getExtras().getInt("score");
AlertDialog.Builder builder = new AlertDialog.Builder(complete.this);
builder.setTitle("Quiz Complete");
builder.setMessage("Your Score is: " +score+ " out of 10");
builder.setPositiveButton("Play Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
Intent intent = new Intent(complete.this, QuizActivity.class);
startActivity(intent);
}
});
builder.setNegativeButton("Done", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void restartQuiz(View view)
{
Intent intent = new Intent(complete.this, QuizActivity.class);
startActivity(intent);
}
public void mainMenu(View view)
{
Intent intent = new Intent(complete.this, MainActivity.class);
startActivity(intent);
}
@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_complete, 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);
}
}
view raw complete.java hosted with ❤ by GitHub


Now, Open strings.xml from res>>values>>strings.xml
Inside resources tag, paste the below code
<string name="question">Please wait....</string>
<string name="answer_one"></string>
<string name="answer_two"></string>
<string name="answer_three"></string>
<string name="answer_four"></string>
<string name="next_questions">Next</string>
<string name="previous_questions">Submit</string>
view raw strings.xml hosted with ❤ by GitHub


Thats all. Now try to run the application. Hoorah..  Thats it.
if you face any errors feel free to comment below. I will try to reply as soon as possible.

Share this

Related Posts

28 comments

comments
May 13, 2016 at 10:00 AM delete This comment has been removed by a blog administrator.
avatar
October 3, 2016 at 11:37 PM delete

how can i download the source code for it

Reply
avatar
October 7, 2016 at 9:57 AM delete

I have'nt published the source code file. Will do if you need it

Reply
avatar
October 20, 2016 at 4:34 AM delete

Could you update for Android Studio 2016? Currently I'm building

Reply
avatar
October 21, 2016 at 2:59 PM delete

The database showme this error when i try to connect it.
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\quiz\quiz.php on line 13
[]

Reply
avatar
October 22, 2016 at 6:35 AM delete

it is an error in your php file. Double check the php file with the one given in the post. Delete the DB and try again with new one

Reply
avatar
October 25, 2016 at 3:02 AM delete

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost; generate error Could you do an instance with the new tools?

Reply
avatar
October 28, 2016 at 3:12 PM delete

Very Informative article. Where can I fnd the source code?

Reply
avatar
November 17, 2016 at 7:23 PM delete

Sir please help. When I start the quiz . Its says Loading pleasewait... but it will Forced Close

Reply
avatar
November 17, 2016 at 7:25 PM delete

First thing is. The php connection. I test it using xamp.
localhost/quiz.php

then it doesnt show the content of my database.

but


Fatal error: Uncaught Error: Call to undefined function mysql_connect() in D:\xampp\htdocs\quiz2.php:7 Stack trace: #0 {main} thrown in D:\xampp\htdocs\quiz2.php on line 7

Reply
avatar
November 17, 2016 at 7:28 PM delete

Id already declare in manifest. what would be the possible error??
sir please help me

Reply
avatar
November 17, 2016 at 7:31 PM delete


android {
useLibrary 'org.apache.http.legacy'
}
paste that to build.gradle

Reply
avatar
November 21, 2016 at 6:38 AM delete

Hi!
How can I build one activity where I can show the result of the test, where I can see which is the correct and incorrect answer.

Reply
avatar
November 22, 2016 at 11:56 PM delete

And other question. Could you show how to do connetion with database in Android Studio 2016? 'cause HTTPCliente and the other libraries are not suportted in A. Studio 2016.

Reply
avatar
December 14, 2016 at 11:42 PM delete

hiii! getting error in isNetworkStatusAvialable(). can you give me solution for this

Reply
avatar
December 16, 2016 at 6:54 AM delete This comment has been removed by the author.
avatar
December 16, 2016 at 8:52 AM delete

where is menu_quiz and menu_complete xml file ?

Reply
avatar
December 18, 2016 at 10:00 AM delete

The correct answer is shown after submitting each question

Reply
avatar
December 18, 2016 at 10:03 AM delete

There is no menu_quiz and menu_complete.xml, only complete.java and activity_complete.xml which is given above

Reply
avatar
December 19, 2016 at 5:43 AM delete

Actually when i run the app the data cant loaded its shown an error unfortunatly the app is not responding

Reply
avatar
December 26, 2016 at 9:46 PM delete

Have you posted the code on Github yet? Would like to download the package and give it a shot. Please help. Thanks.

Reply
avatar
February 5, 2017 at 8:23 AM delete

hello it is showing green color is deprecated..pls help me

Reply
avatar
March 27, 2017 at 5:26 AM delete

Mine too that's my problem in my app. do you already have a solution for this?

Reply
avatar
March 27, 2017 at 9:39 AM delete

i have a error in these lines.if(isNetworkStatusAvialable (getApplicationContext())) {
and the other one is public class QuizActivity extends AppCompatActivity {
and last private class AsyncJsonObject extends AsyncTask

Reply
avatar
September 15, 2017 at 2:26 AM delete

The article is updated with your solution

Reply
avatar
September 24, 2017 at 4:18 AM delete

Where can i get to download full source code. Getting error while running.

Reply
avatar
October 28, 2017 at 2:42 AM delete

I getting problem when the last question will move to the scoring page.

10-28 01:02:25.816 31874-31874/com.example.nuvo.myapplication E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.nuvo.myapplication, PID: 31874 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nuvo.myapplication/com.example.nuvo.myapplication.Complete}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) at android.app.ActivityThread.access$800(ActivityThread.java:166) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5584) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.example.nuvo.myapplication.Complete.onCreate(Complete.java:18) at android.app.Activity.performCreate(Activity.java:5442) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) at android.app.ActivityThread.access$800(ActivityThread.java:166) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5584) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method)

please help me

Reply
avatar

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer