如何解决像java.lang.Throwable:setStateLocked这样的错误?

前端之家收集整理的这篇文章主要介绍了如何解决像java.lang.Throwable:setStateLocked这样的错误?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在开发一个应用程序.在其中我使用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 AsyncTaskPHP" + data;

                URL url = new URL(link);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();

                bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                result = bufferedReader.readLine();
                return result;

            } catch (Exception e) {
                // return new String("Exception: " + e.getMessage());
                // return null;
            }

            return null;
        }


        @Override
        protected void onPostExecute(String result) {

            String jsonStr = result;
            Log.e("TAG",jsonStr);

            if (jsonStr != null) {
                try {
                    JSONObject jsonObj = new JSONObject(jsonStr);
                    String query_result = jsonObj.getString("query_result");
                    if (query_result.equals("SUCCESS")) {
                        Toast.makeText(context,"Success! Your are Now MangoAir User.",Toast.LENGTH_LONG).show();

                    } else if (query_result.equals("FAILURE")) {
                        Toast.makeText(context,"Looks Like you already have Account with US.",Toast.LENGTH_LONG).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    // Toast.makeText(context,"Error parsing JSON Please data Fill all the records.",Toast.LENGTH_SHORT).show();
                    // Toast.makeText(context,"Please LogIn",Toast.LENGTH_SHORT).show();
                    Toast.makeText(context,"Please Login",Toast.LENGTH_LONG).show();

                }
            } else {
                Toast.makeText(context,"Grrr! Check your Internet Connection.",Toast.LENGTH_SHORT).show();
            }
        }

    }


    //List_Search 

    public class List_Search extends AppCompatActivity {

        JSONObject jsonobject;
        JSONArray jsonarray;
        ListView listview;
        ListViewAdapter adapter;
        ProgressDialog mProgressDialog;
        ArrayListPHP");

                try {
                    // Locate the array name in JSON
                    jsonarray = jsonobject.getJSONArray("result");

                    for (int i = 0; i < jsonarray.length(); i++) {
                        HashMap
最佳答案
context.startActivity(intent);

我认为错误是在getview块的btn.setOnClickListener里面的这一行只是使用startActivity(intent);

原文链接:https://www.f2er.com/android/430033.html

猜你在找的Android相关文章