我在AsyncTask
中使用SherlockFragment
并收到此错误并不知道原因
public class MainActivity extends SherlockFragmentActivity {
ViewPager vPager;
PageIndicator pIndicator;
ViewPagerAdapter mAdapter;
private Button cont;
private EditText email;
private HttpClassHandler handler;
private JSONObject jObj;
private static boolean SliderClick = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
strickMode();
initialize();
clicklistners();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
};
private void initialize() {
mAdapter = new ViewPagerAdapter(getSupportFragmentManager());
vPager = (ViewPager) findViewById(R.id.pager);
pIndicator = (PageIndicator) findViewById(R.id.indicator);
vPager.setAdapter(mAdapter);
pIndicator.setViewPager(vPager);
((CirclePageIndicator) pIndicator).setSnap(true);
email = (EditText) findViewById(R.id.email);
cont = (Button) findViewById(R.id.continue_btn);
handler = new HttpClassHandler();
final Handler mHandler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
while (SliderClick) {
try {
Thread.sleep(5000);
mHandler.post(new Runnable() {
@Override
public void run() {
if (vPager.getCurrentItem() == 5) {
vPager.setCurrentItem(0, true);
} else {
vPager.setCurrentItem(
vPager.getCurrentItem() + 1, true);
}
}
});
} catch (Exception e) {
}
}
}
}).start();
}
public void clicklistners() {
vPager.setPageTransformer(false, new ViewPager.PageTransformer() {
@Override
public void transformPage(View page, float position) {
final float normalizedposition = Math.abs(Math.abs(position) - 1);
page.setScaleX(normalizedposition / 2 + 0.5f);
page.setScaleY(normalizedposition / 2 + 0.5f);
}
});
cont.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String user_mail = email.getText().toString();
if (user_mail.equals("")) {
AlertDialog.Builder d = new AlertDialog.Builder(
MainActivity.this);
d.setTitle("Error");
d.setIcon(R.drawable.signup_btn_bg);
d.setMessage("Please Enter Your email");
d.setNeutralButton("OK", null);
d.create();
d.show();
} else {
if (validateEmail(user_mail)) {
AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
ProgressDialog progress;
@Override
protected void onPreExecute() {
super.onPreExecute();
progress = ProgressDialog.show(
MainActivity.this, "Checking Login",
"Please Wait...");
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
progress.dismiss();
if (result) {
Intent i = new Intent(MainActivity.this,
SignInActicity.class);
startActivity(i);
MainActivity.this.onCreate(null);
} else {
try {
Toast.makeText(MainActivity.this,
jObj.getString("message"),
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
protected Boolean doInBackground(Void... params) {
jObj = handler.checkMail(user_mail);
try {
String msg = jObj.getString("success")
.toString();
if (msg.equals("1")) {
return true;
} else if (msg.equals("0")) {
return false;
}
} catch (JSONException e) {
Toast.makeText(MainActivity.this,
"Error occurred", Toast.LENGTH_LONG)
.show();
e.printStackTrace();
}
return false;
}
};
task.execute();
} else {
Toast.makeText(MainActivity.this,
"Enter a Valid Email Address!",
Toast.LENGTH_LONG).show();
}
}
}
});
}
public static boolean validateEmail(String email) {
boolean isValid = false;
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
CharSequence inputStr = email;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}