mReadAgainButton.setOnClickListener(это); вызывает фатальное исключение

Я получаю ошибку принудительного закрытия в строке:

mReadAgainButton.setOnClickListener(this);

и я не уверен, почему. Я просто пытаюсь установить прослушиватель onclick для mReadAgainButton, однако приложение падает с фатальным исключением и очень мало информации в моем логарифме, чтобы предположить, что может быть причиной этого.

ЛОГКАТ:

09-26 15:44:51.540: E/AndroidRuntime(7918): FATAL EXCEPTION: main
09-26 15:44:51.540: E/AndroidRuntime(7918): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.example.settings/com.project.example.settings.ConfigFinalActivity}: java.lang.NullPointerException
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2062)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.ActivityThread.access$600(ActivityThread.java:133)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.os.Looper.loop(Looper.java:137)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.ActivityThread.main(ActivityThread.java:4777)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at java.lang.reflect.Method.invokeNative(Native Method)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at java.lang.reflect.Method.invoke(Method.java:511)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at dalvik.system.NativeStart.main(Native Method)
09-26 15:44:51.540: E/AndroidRuntime(7918): Caused by: java.lang.NullPointerException
09-26 15:44:51.540: E/AndroidRuntime(7918):     at com.project.example.settings.ConfigFinalActivity.onCreate(ConfigFinalActivity.java:141)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.Activity.performCreate(Activity.java:5008)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-26 15:44:51.540: E/AndroidRuntime(7918):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2026)
09-26 15:44:51.540: E/AndroidRuntime(7918):     ... 11 more

ИСТОЧНИК:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int version = android.os.Build.VERSION.SDK_INT;
        tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        update = new UpdateActivity();
        getArrayLists();

        if (ApnArr.isEmpty() || mmscArr.isEmpty()) {

            tryagain();
        } else if (version < VERSION_CODES.ICE_CREAM_SANDWICH) {

            SettingsDbAdapter.setArrayLists(nameArr, ApnArr, mmscArr,
                    mmsproxyArr, mmsportArr, proxyArr, portArr, count,
                    ConfigFinalActivity.this);
            // Update APN table
            try {
                result = updateTable();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }// Settings updated with this atomic call
            catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (result != -1) {
                status = "success";

            } else {
                status = "failure";
            }

            if (status.equals("success")) {
                completeUpdate();
            } else if (status.equals("failure")) {
                tryagain();

            }

        } else {// ICS and later versions

            // Reduce number of steps to 10
            TotalSteps = 10;
            setContentView(R.layout.assist_update);
            String assistUpdate = getString(R.string.instructions_1);
            mAssistUpdateButton = (ImageView) findViewById(R.id.assist_update_btn);
            mAssistUpdateButton.setOnClickListener(this);
            mReadAgainButton = (TextView) findViewById(R.id.read_again_btn);
            mReadAgainButton.setOnClickListener(this);

        }
    }

    private void getArrayLists() {
        nameArr = update.getnameArr();
        ApnArr = update.getApnArr();
        mmscArr = update.getMMSCArr();
        mmsproxyArr = update.getMmscProxyArr();
        mmsportArr = update.getMmsPortArr();
        proxyArr = update.getProxyArr();
        portArr = update.getPortArr();
        count = update.getCount();
        queryResult = update.getResult();
    }

    public void onClick(View v) {
        if (v == mAssistUpdateButton) {

            // Update button for ICS and up is selected
            // Get the TextView in the Assist Update UI

            TextView tv = (TextView) findViewById(R.id.apn_app_text_cta2);
            String text = "";
            CharSequence styledText = text;
            switch (mInstructionNumber) {

            case 0:
                // Retrieve the instruction string resource corresponding the
                // 2nd set of instructions
                text = String.format(getString(R.string.apn_app_text_instr),
                        TotalSteps);
                styledText = Html.fromHtml(text);
                // Update the TextView with the correct set of instructions
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 1:
                text = getString(R.string.apn_app_text_instr2);
                styledText = Html.fromHtml(text);
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 2:
                // Final set of instructions-Change to the corresponding layout

                setContentView(R.layout.assist_instructions);
                String assistUpdateInstr = String.format(
                        getString(R.string.apn_app_text_instr3), TotalSteps);
                styledText = Html.fromHtml(assistUpdateInstr);
                TextView assistInstrText = (TextView) findViewById(R.id.updated_text);
                assistInstrText.setText(styledText);
                mAssistInstrButton = (Button) findViewById(R.id.assist_instr_btn);
                mAssistInstrButton.setOnClickListener(this);

            }
        } else if (v == mAssistInstrButton) {
            // "LET'S DO THIS" Button in final instructions screen for ICS and
            // up is selected
            Values = getValues();
            startActivity(new Intent(Settings.ACTION_APN_SETTINGS));
            try {
                showNotification();
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            finish();
        } else if (v == mAssistInstrButton) {
            startActivity(new Intent(Settings.ACTION_APN_SETTINGS));
            try {
                showNotification();
            } catch (SAXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (ParserConfigurationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            try {
                showNotification();
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            finish();

        } else if (v == mReadAgainButton) {
            // go back to set of instructions if read again is selected

            TextView tv = (TextView) findViewById(R.id.apn_app_text_cta2);
            String text = "";
            CharSequence styledText = text;
            switch (mInstructionNumber) {

            case 0:
                // Retrieve the instruction string resource corresponding the
                // 2nd set of instructions
                text = String.format(getString(R.string.apn_app_text_instr),
                        TotalSteps);
                styledText = Html.fromHtml(text);
                // Update the TextView with the correct set of instructions
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 1:
                text = getString(R.string.apn_app_text_instr2);
                styledText = Html.fromHtml(text);
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 2:
                // Final set of instructions-Change to the corresponding layout

                setContentView(R.layout.assist_instructions);
                String assistUpdateInstr = String.format(
                        getString(R.string.apn_app_text_instr3), TotalSteps);
                styledText = Html.fromHtml(assistUpdateInstr);
                TextView assistInstrText = (TextView) findViewById(R.id.updated_text);
                assistInstrText.setText(styledText);
                mAssistInstrButton = (Button) findViewById(R.id.assist_instr_btn);
                mAssistInstrButton.setOnClickListener(this);

            }
        }
    }

person Wendy    schedule 26.09.2013    source источник
comment
Что находится в строке 141 из ConfigFinalActivity? И если это, UpdateActivity, является фактическим Activity, тогда вам не следует создавать его таким, какой вы есть.   -  person codeMagic    schedule 26.09.2013
comment
Я вижу много операторов, которые вызывают NPE.   -  person Vipul    schedule 26.09.2013
comment
См. этот ответ о том, как читать logcat.   -  person codeMagic    schedule 26.09.2013
comment
141 — это mAssistUpdateButton.setOnClickListener(это);   -  person Wendy    schedule 27.09.2013
comment
Я понимаю, что это указывает на строку 141 - я просто не понимаю, в чем проблема с mAssistUpdateButton.setOnClickListener(this); может быть.   -  person Wendy    schedule 27.09.2013
comment
Возвращает ли предыдущая строка экземпляр ImageView или null?   -  person Szymon    schedule 27.09.2013
comment
Проверьте свой assist_update.xml на предмет ImageView, который вы пытаетесь создать. Если это строка, которую вы получаете NPE, то это означает, что assist_update_btn не является id из ImageView в этом layout. Убедитесь, что вы не ошиблись.   -  person codeMagic    schedule 27.09.2013
comment
Я проверил... он действительно содержит мой Assist_update_btn ImageView.   -  person Wendy    schedule 27.09.2013