java throwable判断,如何解决像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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值