我有一个问题: - 当我在代码中使用对话框或吐司时,显示以下错误:方法OnCreate(Bundle)类型MainActivity必须覆盖或实现超类型方法。
所以我测试了jdk编译器1.5,1.6和1.7的3状态,但它不起作用。 有什么问题?
public class MainActivity extends Activity {
boolean stopCopy = false;
boolean stopDelete = false;
boolean isCopy = false;
boolean isDelete = false;
private ProgressBar pr;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText edittxt_start_copy = (EditText) findViewById(R.id.edittxt_start_num);
final EditText edittxt_end_copy = (EditText) findViewById(R.id.edittxt_end_num);
final Button btn_start_copy = (Button) findViewById(R.id.btn_start_copy);
pr = (ProgressBar) findViewById(R.id.progressBar);
pr.setVisibility(View.GONE);
final EditText edittext_start_delete = (EditText) findViewById(R.id.edittxt_start_delete);
final EditText edittext_end_delete = (EditText) findViewById(R.id.edittxt_end_delete);
final Button btn_start_delete = (Button) findViewById(R.id.btn_start_delete);
btn_start_copy.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(!isCopy)
{
btn_start_copy.setText("STOP");
pr.setVisibility(View.VISIBLE);
stopCopy = false;
// Check if no view has focus:
View view = MainActivity.this.getCurrentFocus();
if (view != null)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
final String start_str_copy = edittxt_start_copy.getText().toString();
String end_str_copy = edittxt_end_copy.getText().toString();
final String start_num_copy = start_str_copy.substring(4,11);
final String end_num_copy = end_str_copy.substring(4,11);
if (start_str_copy.length() < 11 || end_str_copy.length() < 11)
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("خطا").setMessage("شماره وارد شده باید یازده رقمی باشد");
AlertDialog alert = builder.create();
alert.show();
}
else
{
Thread copy = new Thread(new Runnable()
{
@Override
public void run()
{
final int total[] = new int [1];
total[0] = 0;
long start = Integer.parseInt(start_num_copy);
long end = Integer.parseInt(end_num_copy);
int counter = (int) (end - start);
pr.setMax(counter);
int i;
for (i = 0; i <= counter && !stopCopy; i++)
{
total[0] += 1;
pr.post(new Runnable() {
@Override
public void run() {
pr.setProgress(total[0]);
}
});
int k = 7 - String.valueOf(start + i).length();
String zero = "0000000" ;
String MobileNumber = start_str_copy.substring(0,4) + zero.substring(0,k) + String.valueOf(start + i);
String DisplayName = start_str_copy.substring(0,4) + zero.substring(0,k) + String.valueOf(start + i);
ArrayList < ContentProviderOperation > ops = new ArrayList < ContentProviderOperation > ();
ops.add(ContentProviderOperation.newInsert(
ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
//------------------------------------------------------ Names
if (DisplayName != null)
{
ops.add(ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
DisplayName).build());
}
//------------------------------------------------------ Mobile Number
if (MobileNumber != null)
{
ops.add(ContentProviderOperation.
newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, MobileNumber)
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
.build());
}
// Asking the Contact provider to create a new contact
try
{
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (Exception e)
{
e.printStackTrace();
//Toast.makeText(this, "Exception: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
if (i == counter +1)
{
pr.post(new Runnable() {
public void run() {
pr.setVisibility(View.GONE);
}
});
btn_start_copy.post(new Runnable() {
@Override
public void run() {
btn_start_copy.setText("START");
}
});
isCopy = !isCopy;
}
}
});copy.start();
}
}
else
{
stopCopy = true;
btn_start_copy.setText("START");
pr.setVisibility(View.GONE);
}
isCopy = !isCopy;
}
});
请帮帮我。感谢