This is the main activity. I was trying to retrieve the value of EDIBLE PORTION which is INTEGER. But the problem is when I run it, It crashed, i don't know why need some help here. package com.apk.foodanalyzer.healthandnutrifactsanalyzer;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.apk.foodanalyzer.healthandnutrifactsanalyzer.goactivity.DatabaseHelper;
import com.apk.foodanalyzer.healthandnutrifactsanalyzer.goactivity.DoBackEnd;
import com.apk.foodanalyzer.healthandnutrifactsanalyzer.goactivity.GoItem;
import com.apk.foodanalyzer.healthandnutrifactsanalyzer.goactivity.GoItemContent;
import java.sql.RowId;
/**
* Created by Pavilion on 11/29/2015.
*/
public class GoValueActivityContent extends AppCompatActivity {
private TextView FoodDescription, Scientificname, AlternateName,EdiblePortion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gocontent_layout);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
int dictionaryId = bundle.getInt("RowId");
int search = dictionaryId + 1;
FoodDescription = (TextView)findViewById(R.id.go_conent_fooddescription);
Scientificname = (TextView)findViewById(R.id.go_conent_scientificname);
AlternateName = (TextView)findViewById(R.id.go_content_alternatename);
EdiblePortion = (TextView)findViewById(R.id.goedibleportion_value);
DoBackEnd dbBackend = new DoBackEnd(GoValueActivityContent.this);
GoItemContent allQuizQuestions = dbBackend.getQuizById(search);
FoodDescription.setText(allQuizQuestions.getFoodDescription());
Scientificname.setText(allQuizQuestions.getScientificName());
AlternateName.setText(allQuizQuestions.getAlternateName());
EdiblePortion.setText(allQuizQuestions.getEdiblePortion());
}
}
This is the Object
public class GoItemContent {
private String FoodDescription;
private String ScientificName;
private String AlternateName;
private Integer EdiblePortion;
public GoItemContent(String foodDescription, String scientificName, String alternateName, Integer ediblePortion) {
FoodDescription = foodDescription;
ScientificName = scientificName;
AlternateName = alternateName;
EdiblePortion = ediblePortion;
}
public String getFoodDescription() {
return FoodDescription;
}
public void setFoodDescription(String foodDescription) {
FoodDescription = foodDescription;
}
public String getScientificName() {
return ScientificName;
}
public void setScientificName(String scientificName) {
ScientificName = scientificName;
}
public String getAlternateName() {
return AlternateName;
}
public void setAlternateName(String alternateName) {
AlternateName = alternateName;
}
public Integer getEdiblePortion() {
return EdiblePortion;
}
public void setEdiblePortion(Integer ediblePortion) {
EdiblePortion = ediblePortion;
}
}
and my METHOD
public GoItemContent getQuizById(int quizId){
GoItemContent quizObject = null;
String query = "SELECT FoodDescription, ScientificName, AlternateName, EdiblePortion FROM GoTable WHERE RowId = " + quizId;
Cursor cursor = this.getDbConnection().rawQuery(query, null);
if(cursor.moveToFirst()){
do{
String fooddescription = cursor.getString(cursor.getColumnIndexOrThrow("FoodDescription"));
String scientificname = cursor.getString(cursor.getColumnIndexOrThrow("ScientificName"));
String alternatename = cursor.getString(cursor.getColumnIndexOrThrow("AlternateName"));
int edibleportion = cursor.getInt(cursor.getColumnIndexOrThrow("EdiblePortion"));
quizObject = new GoItemContent(fooddescription,scientificname,alternatename,edibleportion);
}while(cursor.moveToNext());
}
cursor.close();
return quizObject;
}
Thank you in advance. :)
Aucun commentaire:
Enregistrer un commentaire