No such instance field java

Нет такого экземпляра поля

Я понятия не имею, почему, поскольку я объявляю его значением false при запуске операции и меняю его на true, если нажата кнопка. Может кто-нибудь мне помочь?

package com.bignerdranch.android.geoquiz; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; /** * Created by Chris on 20/02/2015. */ public class CheatActivity extends Activity < public static final String EXTRA_ANSWER_IS_TRUE = "com.bignerdranch.android.geoquiz.answer_is_true"; public static final String EXTRA_ANSWER_SHOWN = "com.bignerdranch.android.geoquiz.answer_shown"; private static final String KEY_INDEX = "index"; private boolean mAnswerIsTrue; private TextView mAnswerTextView; private Button mShowAnswer; private boolean mCheated = false; private void setAnswerShownResult(boolean isAnswerShown) < Intent data = new Intent(); data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown); setResult(RESULT_OK, data); >@Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_cheat); mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE,false); if (savedInstanceState != null)< mCheated = savedInstanceState.getBoolean(KEY_INDEX, mCheated); >setAnswerShownResult(mCheated); mAnswerTextView = (TextView)findViewById(R.id.answerTextView); mShowAnswer = (Button)findViewById(R.id.showAnswerButton); mShowAnswer.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < if (mAnswerIsTrue) < mAnswerTextView.setText(R.string.true_button); >else < mAnswerTextView.setText(R.string.false_button); >setAnswerShownResult(true); mCheated = true; > >); > @Override public void onSaveInstanceState(Bundle savedInstanceState) < super.onSaveInstanceState(savedInstanceState); //Log.i(TAG, "onSaveInstanceState"); savedInstanceState.putBoolean(KEY_INDEX, mCheated); >> 

Источник

Нет такого экземпляра поля

Я пытаюсь заставить мое приложение сохранять некоторые данные, когда ориентация экрана изменяется с помощью onSaveInstanceState , чтобы сохранить логическое значение mCheated . Я установил множество точек останова и получаю ошибку для mCheated логического значения в представлении переменных

mCheated= No such instance field: 'mCheated' 

Я понятия не имею, почему, когда я объявляю его со значением false при запуске действия и изменяю его на true, если нажата кнопка. Может ли кто-нибудь помочь мне?

package com.bignerdranch.android.geoquiz; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; /** * Created by Chris on 20/02/2015. */ public class CheatActivity extends Activity < public static final String EXTRA_ANSWER_IS_TRUE = "com.bignerdranch.android.geoquiz.answer_is_true"; public static final String EXTRA_ANSWER_SHOWN = "com.bignerdranch.android.geoquiz.answer_shown"; private static final String KEY_INDEX = "index"; private boolean mAnswerIsTrue; private TextView mAnswerTextView; private Button mShowAnswer; private boolean mCheated = false; private void setAnswerShownResult(boolean isAnswerShown) < Intent data = new Intent(); data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown); setResult(RESULT_OK, data); >@Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_cheat); mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE,false); if (savedInstanceState != null)< mCheated = savedInstanceState.getBoolean(KEY_INDEX, mCheated); >setAnswerShownResult(mCheated); mAnswerTextView = (TextView)findViewById(R.id.answerTextView); mShowAnswer = (Button)findViewById(R.id.showAnswerButton); mShowAnswer.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < if (mAnswerIsTrue) < mAnswerTextView.setText(R.string.true_button); >else < mAnswerTextView.setText(R.string.false_button); >setAnswerShownResult(true); mCheated = true; > >); > @Override public void onSaveInstanceState(Bundle savedInstanceState) < super.onSaveInstanceState(savedInstanceState); //Log.i(TAG, "onSaveInstanceState"); savedInstanceState.putBoolean(KEY_INDEX, mCheated); >> 

Где получить mCheated= No such instance field: ‘mCheated’ ошибка mCheated= No such instance field: ‘mCheated’ ?

Читайте также:  Дипломная работа публикование мультимедиа контента средствами языка разметки html

Когда я использую точку останова для отладки экземпляров mCheated, таких как строка «saveInstanceState.putBoolean (KEY_INDEX, mCheated);» и ‘mCheated = true;’

Источник

Нет такого экземпляра поля

Я понятия не имею, почему, поскольку я объявляю его значением false при запуске операции и меняю его на true, если нажата кнопка. Может кто-нибудь мне помочь?

package com.bignerdranch.android.geoquiz; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; /** * Created by Chris on 20/02/2015. */ public class CheatActivity extends Activity < public static final String EXTRA_ANSWER_IS_TRUE = "com.bignerdranch.android.geoquiz.answer_is_true"; public static final String EXTRA_ANSWER_SHOWN = "com.bignerdranch.android.geoquiz.answer_shown"; private static final String KEY_INDEX = "index"; private boolean mAnswerIsTrue; private TextView mAnswerTextView; private Button mShowAnswer; private boolean mCheated = false; private void setAnswerShownResult(boolean isAnswerShown) < Intent data = new Intent(); data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown); setResult(RESULT_OK, data); >@Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_cheat); mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE,false); if (savedInstanceState != null)< mCheated = savedInstanceState.getBoolean(KEY_INDEX, mCheated); >setAnswerShownResult(mCheated); mAnswerTextView = (TextView)findViewById(R.id.answerTextView); mShowAnswer = (Button)findViewById(R.id.showAnswerButton); mShowAnswer.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < if (mAnswerIsTrue) < mAnswerTextView.setText(R.string.true_button); >else < mAnswerTextView.setText(R.string.false_button); >setAnswerShownResult(true); mCheated = true; > >); > @Override public void onSaveInstanceState(Bundle savedInstanceState) < super.onSaveInstanceState(savedInstanceState); //Log.i(TAG, "onSaveInstanceState"); savedInstanceState.putBoolean(KEY_INDEX, mCheated); >> 

Источник

No such instance field

I’m trying to get my application to save some data when the orientation of the screen is changed using the onSaveInstanceState to save a boolean value mCheated .

I’ve set numerous break points and am getting an error for the mCheated boolean value in the variables view

mCheated= No such instance field: 'mCheated' 

I have no idea why as I declare it with a value false when the activity is started and change it to true if a button is pressed. Can anyone help me out?

package com.bignerdranch.android.geoquiz; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; /** * Created by Chris on 20/02/2015. */ public class CheatActivity extends Activity < public static final String EXTRA_ANSWER_IS_TRUE = "com.bignerdranch.android.geoquiz.answer_is_true"; public static final String EXTRA_ANSWER_SHOWN = "com.bignerdranch.android.geoquiz.answer_shown"; private static final String KEY_INDEX = "index"; private boolean mAnswerIsTrue; private TextView mAnswerTextView; private Button mShowAnswer; private boolean mCheated = false; private void setAnswerShownResult(boolean isAnswerShown) < Intent data = new Intent(); data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown); setResult(RESULT_OK, data); >@Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_cheat); mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE,false); if (savedInstanceState != null)< mCheated = savedInstanceState.getBoolean(KEY_INDEX, mCheated); >setAnswerShownResult(mCheated); mAnswerTextView = (TextView)findViewById(R.id.answerTextView); mShowAnswer = (Button)findViewById(R.id.showAnswerButton); mShowAnswer.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < if (mAnswerIsTrue) < mAnswerTextView.setText(R.string.true_button); >else < mAnswerTextView.setText(R.string.false_button); >setAnswerShownResult(true); mCheated = true; > >); > @Override public void onSaveInstanceState(Bundle savedInstanceState) < super.onSaveInstanceState(savedInstanceState); //Log.i(TAG, "onSaveInstanceState"); savedInstanceState.putBoolean(KEY_INDEX, mCheated); >> 

algorhythm

1 Answers

It turns out there wasn’t a problem with the code and that Android Studio required a restart. I think it was down to the fact I had cloned the project and was possibly using an incorrect file from the previous version.

Источник

No such instance field

It turns out there wasn’t a problem with the code and that Android Studio required a restart. I think it was down to the fact I had cloned the project and was possibly using an incorrect file from the previous version.

Solution 3

I had the same error. The solution to the error is to disable the Proguard in build.gradle file.

Solution 4

I got the same error and I wasted my 3-4 hours to resolve same error finally I got to know why that happened and it was interesting

  1. In my case, I changed the code in one file (I declared one variable and initialized it)
  2. I run the apk from my device and attached debugger from android studio
  3. I set debug point to that newly added variable where I assigned data to it
  4. but during debugging it shows me same error
  5. Then I got to know I changed the code in file but I run the apk from device, and I attached debugger I need to compile and run the changes instead of it how it will reflect in apk that was the actual issue
  6. So I compiled and ran the code and installed newly compiled apk on device then I attached debugger and it worked for me

hope this will save someone’s time

Solution 5

If you’re using pro-guard and obfuscation is true. you have to comment out obfuscation in build gradle

eg: add this in the pro-guard -dontobfuscate

Advanced Pivot Table Techniques (to achieve more in Excel)

Sữa lỗi No such file or Directory trên Arduino IDE / How to fix errors: No such file or Directory

How to be Excited | No Hard Feelings - Week 4

Supersymmetry, explained visually

Preparing The

Instance Fields, Methods, and Constructors

How To Handle No Such Element Exception - Selenium WebDriver Tutorial

How can I log into my Amazon EC2 instance if I receive an error that the server refused our key?

AWS Knowledge Center Videos: How do I recover access to my EC2 instances if I lost my SSH key pair?

MVC - Fix Error - A namespace cannot directly contain members such as fields or methods

Error arduino: No such file or directory.

SNIPERS in MASTODONS are absolutely BROKEN! 😨

There's no such thing as MIRACLE, Richard Feynman advice to students | self-improvement video

Adams Arms AA19 [Field Strip] Disassembly & Reassembly

algorhythm

I am a software support engineer for a company that develops and maintains traffic management software.

Comments

I’m trying to get my application to save some data when the orientation of the screen is changed using the onSaveInstanceState to save a boolean value mCheated . I’ve set numerous break points and am getting an error for the mCheated boolean value in the variables view

mCheated= No such instance field: 'mCheated' 

I have no idea why as I declare it with a value false when the activity is started and change it to true if a button is pressed. Can anyone help me out?

package com.bignerdranch.android.geoquiz; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; /** * Created by Chris on 20/02/2015. */ public class CheatActivity extends Activity < public static final String EXTRA_ANSWER_IS_TRUE = "com.bignerdranch.android.geoquiz.answer_is_true"; public static final String EXTRA_ANSWER_SHOWN = "com.bignerdranch.android.geoquiz.answer_shown"; private static final String KEY_INDEX = "index"; private boolean mAnswerIsTrue; private TextView mAnswerTextView; private Button mShowAnswer; private boolean mCheated = false; private void setAnswerShownResult(boolean isAnswerShown) < Intent data = new Intent(); data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown); setResult(RESULT_OK, data); >@Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_cheat); mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE,false); if (savedInstanceState != null)< mCheated = savedInstanceState.getBoolean(KEY_INDEX, mCheated); >setAnswerShownResult(mCheated); mAnswerTextView = (TextView)findViewById(R.id.answerTextView); mShowAnswer = (Button)findViewById(R.id.showAnswerButton); mShowAnswer.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < if (mAnswerIsTrue) < mAnswerTextView.setText(R.string.true_button); >else < mAnswerTextView.setText(R.string.false_button); >setAnswerShownResult(true); mCheated = true; > >); > @Override public void onSaveInstanceState(Bundle savedInstanceState) < super.onSaveInstanceState(savedInstanceState); //Log.i(TAG, "onSaveInstanceState"); savedInstanceState.putBoolean(KEY_INDEX, mCheated); >> 

When I use a breakpoint to debug instances of mCheated such as the line ‘savedInstanceState.putBoolean(KEY_INDEX, mCheated);’ and ‘mCheated = true;’

Android is everything for me

Though restart android studio helped you but it is not actual solution. If you really walk through your problem you will understand the actual issue. I have answered it above please have a look into it. 🙂

Источник

Оцените статью