Je les gens, j'ai une grande question: je crée ma première application Android avec Db, et c'est ma deuxième semaine avec Java et OOP.ne peut pas être résolu
C'est la source de l'activité principale:
public class EpsoftSMSActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final MyDatabase db=new MyDatabase(getApplicationContext());
db.open(); //apriamo il db
if (db.listaParametri().getCount()==0)
{
setup_parametri();
/*final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.login);
dialog.setTitle("Login");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
//set up button
Button registra = (Button) dialog.findViewById(R.id.registra);
registra.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String username = dialog.findViewById(R.id.username).toString();
String password = dialog.findViewById(R.id.password).toString();
db.inserimentoParametri(username, password);
dialog.dismiss();
}
});
Button annulla = (Button) dialog.findViewById(R.id.annulla);
annulla.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();*/
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.layout.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.chiudi:
finish();
System.exit(0);
return true;
case R.id.setup:
setup_parametri();
return true;
case R.id.info:
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Informazioni & Credits");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
/* //set up text
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
//text.setText(R.string.lots_of_text);
//set up image view
ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
img.setImageResource(R.drawable.ic_launcher);*/
//set up button
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
return true;
}
return super.onOptionsItemSelected(item);
}
public void setup_parametri()
{
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.login);
dialog.setTitle("Login");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
//set up button
Button registra = (Button) dialog.findViewById(R.id.registra);
registra.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String username = dialog.findViewById(R.id.username).toString();
String password = dialog.findViewById(R.id.password).toString();
db.inserimentoParametri(username, password);
dialog.dismiss();
}
});
Button annulla = (Button) dialog.findViewById(R.id.annulla);
annulla.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
}
Dans la dernière fonction, appelée « setup_parametri » j'essaie d'appeler « db.inserimentoParametri », mais Eclipse me dire « db ne peut pas être résolu ». Db est défini dans l'oncreate.
Qu'est-ce que c'est? Tnx.
J'ai essayé (dans mon ignorance réelle sur OOP) de déclarer DB avant l'oncreate. Résultat: aucune erreur dans la compilation mais erreur dans l'exécution. –
Quelle est l'erreur? Comment l'avez-vous déclaré? –
Je le déclare dans le même mode avant le premier @override. L'erreur est présente 6 à 9 janvier: 27: 16,252: E/AndroidRuntime (278) causés par: java.lang.NullPointerException janvier 6 à 9: 27: 16,252: E/AndroidRuntime (278): \t at android.content.ContextWrapper.getApplicationContext (ContextWrapper.java:100) –