Android:空指针异常问题

时间:2015-12-05 08:47:37

标签: java android sqlite nullpointerexception

请帮助。这段代码有什么错误?我想在数据库中检索文本(句子容器20个或更多单词)。我可以通过这个程序检索它吗?提前谢谢。

package com.apk.foodanalyzer.healthandnutrifactsanalyzer;

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.GoItemContent;
import com.apk.foodanalyzer.healthandnutrifactsanalyzer.growactivity.GrowBackEnd;
import com.apk.foodanalyzer.healthandnutrifactsanalyzer.growactivity.GrowItemContent;

/**
 * Created by Pavilion on 12/1/2015.
 */
public class GrowValueActivityContent extends AppCompatActivity{

    private TextView FoodDescription, Scientificname, AlternateName,EdiblePortion,
            Water,Energy,Protein,Fat,Carbohydrate,Crudefiber,Ash,Calcium,Phosphorus,Iron,Retinol,
            Carotene,VitA,Thiamin,Riboflavin,Niacin,AscorbicAcid, Postip,Negatip;
    @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);
        Water = (TextView)findViewById(R.id.water_value);
        Energy = (TextView)findViewById(R.id.energy_value);
        Protein = (TextView)findViewById(R.id.protein_value);
        Fat = (TextView)findViewById(R.id.fat_value);
        Carbohydrate = (TextView)findViewById(R.id.carbohydrate_value);
        Crudefiber = (TextView)findViewById(R.id.crudefiber_value);
        Ash = (TextView)findViewById(R.id.ash_value);
        Calcium = (TextView)findViewById(R.id.calcium_value);
        Phosphorus = (TextView)findViewById(R.id.phosphorus_value);
        Iron = (TextView)findViewById(R.id.iron_value);
        Retinol = (TextView)findViewById(R.id.retinol_value);
        Carotene = (TextView)findViewById(R.id.carotene_value);
        VitA = (TextView)findViewById(R.id.vitamina_value);
        Thiamin = (TextView)findViewById(R.id.thiamin_value);
        Riboflavin = (TextView)findViewById(R.id.riboflavin_value);
        Niacin = (TextView)findViewById(R.id.niacin_value);
        AscorbicAcid = (TextView)findViewById(R.id.ascorbicacid_value);
        Postip = (TextView) findViewById(R.id.txtvx_tippos);
        Negatip = (TextView)findViewById(R.id.txtvx_tipneg);


        GrowBackEnd dbBackend = new GrowBackEnd(GrowValueActivityContent.this);
        GrowItemContent allQuizQuestions = dbBackend.getQuizById(search);

        FoodDescription.setText(allQuizQuestions.getFoodDescription());
        Scientificname.setText(allQuizQuestions.getScientificName());
        AlternateName.setText(allQuizQuestions.getAlternateName());

        EdiblePortion.setText(String.valueOf(allQuizQuestions.getEdiblePortion())  + " g");
        Water.setText(String.valueOf(allQuizQuestions.getWater())  + " g");
        Energy.setText(String.valueOf(allQuizQuestions.getEnergy()) + " kcal");
        Protein.setText(String.valueOf(allQuizQuestions.getProtein())  + " g");
        Fat.setText(String.valueOf(allQuizQuestions.getFat())  + " g");
        Carbohydrate.setText(String.valueOf(allQuizQuestions.getCarbohydrate()) + " g");
        Crudefiber.setText(String.valueOf(allQuizQuestions.getCrudefiber()) + " g");
        Ash.setText(String.valueOf(allQuizQuestions.getAsh()) + " g");
        Calcium.setText(String.valueOf(allQuizQuestions.getCalcium()) + " mg");
        Phosphorus.setText(String.valueOf(allQuizQuestions.getPhosphorus())  + " mg");
        Iron.setText(String.valueOf(allQuizQuestions.getIron()) + " mg");
        Retinol.setText(String.valueOf(allQuizQuestions.getRetinol())  + "  ");
        Carotene.setText(String.valueOf(allQuizQuestions.getCarotene()));
        VitA.setText(String.valueOf(allQuizQuestions.getVitA()));
        Thiamin.setText(String.valueOf(allQuizQuestions.getThiamin()) + " mg");
        Riboflavin.setText(String.valueOf(allQuizQuestions.getRiboflavin()) + " mg");
        Niacin.setText(String.valueOf(allQuizQuestions.getNiacin()) + " mg");
        AscorbicAcid.setText(String.valueOf(allQuizQuestions.getAscorbicAcid()) + " mg");

        Postip.setText(String.valueOf(allQuizQuestions.getPositiveTip()));
        //Negatip.setText(allQuizQuestions.getNegativeTip());

    }

}

这是LOGCAT显示的。 :(

12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime: FATAL EXCEPTION: main
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime: Process: com.apk.foodanalyzer.healthandnutrifactsanalyzer, PID: 26713
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apk.foodanalyzer.healthandnutrifactsanalyzer/com.apk.foodanalyzer.healthandnutrifactsanalyzer.GrowValueActivityContent}: java.lang.NullPointerException
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2386)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2438)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:160)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:110)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5368)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:  Caused by: java.lang.NullPointerException
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at com.apk.foodanalyzer.healthandnutrifactsanalyzer.GrowValueActivityContent.onCreate(GrowValueActivityContent.java:83)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5369)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2340)
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2438) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:160) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:110) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5368) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
12-05 16:38:33.602 26713-26713/com.apk.foodanalyzer.healthandnutrifactsanalyzer E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 

这是什么意思造成的:java.lang.NullPointerException?

0 个答案:

没有答案