我在下面的代码中收到以下错误,我找不到解决方案,您能帮忙
代码:
public class MainActivity extends AppCompatActivity {
private Button buttonGetir,buttonSil,buttonGuncelle,buttonKaydet;
private TextView textViewCikti;
private EditText editTextId,editTextAd,editTextTel;
static final String PROVIDER_NAME ="info.com.MyProvider";
static final String URL="content://"+PROVIDER_NAME+"/rehber";
static final Uri CONTENT_URI = Uri.parse(URL);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonGetir = findViewById(R.id.buttonGetir);
buttonSil = findViewById(R.id.buttonSil);
buttonGuncelle = findViewById(R.id.buttonGuncelle);
buttonKaydet = findViewById(R.id.buttonKaydet);
textViewCikti =findViewById(R.id.textViewCikti);
editTextAd = findViewById(R.id.editTextAd);
editTextId = findViewById(R.id.editTextId);
editTextTel = findViewById(R.id.editTextTel);
buttonKaydet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ContentValues values= new ContentValues();
values.put("ad",editTextAd.getText().toString());
values.put("tel",editTextTel.getText().toString());
Uri uri = getContentResolver().insert(CONTENT_URI,values);
Toast.makeText(MainActivity.this, "Rehber : "+uri.toString()+"Kayıt Edildi", Toast.LENGTH_SHORT).show();
}
});
buttonGetir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Cursor c = getContentResolver().query(CONTENT_URI,null,null,null,null);
String result ="Rehber sonuç : ";
while (c.moveToNext()){
result =result + "\n"+c.getInt(c.getColumnIndex("id"))
+"--"+c.getString(c.getColumnIndex("ad"))
+"--"+c.getString(c.getColumnIndex("tel"));
}
textViewCikti.setText(result);
}
});
buttonSil.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri = Uri.parse("content://info.com.MyProvider/rehber/"+editTextId.getText().toString());
int count = getContentResolver().delete(uri,null,null);
}
});
buttonGuncelle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ContentValues values= new ContentValues();
values.put("ad",editTextAd.getText().toString());
values.put("tel",editTextTel.getText().toString());
Uri uri = Uri.parse("content://info.com.MyProvider/rehber/"+editTextId.getText().toString());
int count = getContentResolver().update(uri,values,null,null);
}
});
}
}
E / ActivityThread:无法找到info.com.MyProvider的提供者信息。 D / AndroidRuntime:关闭VM E / AndroidRuntime:致命异常:main 流程:info.com,PID:3076 java.lang.NullPointerException:尝试在空对象引用上调用接口方法'boolean android.database.Cursor.moveToNext()' 在info.com.MainActivity $ 2.onClick(MainActivity.java:58) 在android.view.View.performClick(View.java:5609) 在android.view.View $ PerformClick.run(View.java:22259) 在android.os.Handler.handleCallback(Handler.java:751) 在android.os.Handler.dispatchMessage(Handler.java:95) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6077) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)