我正在开发一个应用程序.在其中我使用ListvIEw.当我点击列表项时,它应该转到下一个活动,即ProfileActivity2.java.它工作正常,但在这个ProfileActivty2底部有一个按钮,当我点击这个按钮时,我的应用程序崩溃并停在ListvIEw页面中.并在ListvIEw布局文件中显示错误java.lang.Throwable:setStateLocked,即setContentVIEw.我该如何解决这个错误?
//ProfileActivity2.java public class ProfileActivity2 extends AppCompatActivity { //TextvIEw to show currently logged in user private TextVIEw textVIEw; private boolean loggedIn = false; button btn; EditText edname,edaddress; TextVIEw tvsname,tvsprice; NumberPicker numberPicker; TextVIEw textvIEw1,textvIEw2; Integer temp; String pname,paddress,email,sname,sprice; @OverrIDe protected voID onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_profile1); //Initializing textvIEw textVIEw = (TextVIEw) findVIEwByID(R.ID.textVIEw); edname=(EditText)findVIEwByID(R.ID.ed_pname); edaddress=(EditText)findVIEwByID(R.ID.ed_add); tvsname=(TextVIEw)findVIEwByID(R.ID.textVIEw_name); tvsprice=(TextVIEw)findVIEwByID(R.ID.textVIEw2_price); btn=(button)findVIEwByID(R.ID.button); Intent i = getIntent(); // getting attached intent data String name = i.getStringExtra("sname"); // displaying selected product name tvsname.setText(name); String price = i.getStringExtra("sprice"); // displaying selected product name tvsprice.setText(price); numberPicker = (NumberPicker)findVIEwByID(R.ID.numberpicker); numberPicker.setMinValue(0); numberPicker.setMaxValue(4); final int foo = Integer.parseInt(price); textvIEw1 = (TextVIEw)findVIEwByID(R.ID.textVIEw1_amount); textvIEw2 = (TextVIEw)findVIEwByID(R.ID.textVIEw_seats); // numberPicker.setValue(foo); numberPicker.setonValueChangedListener(new NumberPicker.OnValuechangelistener() { @OverrIDe public voID onValueChange(NumberPicker picker,int oldVal,int newVal) { temp = newVal * foo; // textvIEw1.setText("Selected Amount : " + temp); // textvIEw2.setText("Selected Seats : " + newVal); textvIEw1.setText(String.valueOf(temp)); textvIEw2.setText(String.valueOf(newVal)); // textvIEw1.setText(temp); // textvIEw2.setText(newVal); } }); //Fetching email from shared preferences btn.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // submitForm(); // Intent intent = new Intent(ProfileActivity2.this,SpinnerActivity.class); // startActivity(intent); SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_name,Context.MODE_PRIVATE); loggedIn = sharedPreferences.getBoolean(Config.LOGGEDIN_SHARED_PREF,false); String email = sharedPreferences.getString(Config.EMAIL_SHARED_PREF,"Not Available"); textVIEw.setText(email); if(loggedIn){ submitForm(); Intent intent = new Intent(ProfileActivity2.this,SpinnerActivity.class); startActivity(intent); } } }); } private voID submitForm() { // submit your form here. your form is valID //Toast.makeText(this,"submitting form...",Toast.LENGTH_LONG).show(); String pname = edname.getText().toString(); String paddress = edaddress.getText().toString(); String sname = textvIEw1.getText().toString(); // String sname= String.valueOf(textvIEw1.getText().toString()); String sprice= textvIEw2.getText().toString(); // String sprice= String.valueOf(textvIEw2.getText().toString()); String email= textVIEw.getText().toString(); Toast.makeText(this,"Signing up...",Toast.LENGTH_SHORT).show(); new SignupActivity(this).execute(pname,sprice,email); } } //SignupActivity public class SignupActivity extends AsyncTask
最佳答案context.startActivity(intent);
我认为错误是在getvIEw块的btn.setonClickListener里面的这一行只是使用startActivity(intent); 总结
以上是内存溢出为你收集整理的如何解决像java.lang.Throwable:setStateLocked这样的错误?全部内容,希望文章能够帮你解决如何解决像java.lang.Throwable:setStateLocked这样的错误?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)