0
私はここで同様の記事を読んだことがありますが、これらの回答で結果を得ることはできません。私は、カスタムダイアログ内のSQLiteからスピナーを移入しようとしているが、私はs.setAdapter(データソース)で例外を取得し、特定の行にSQLiteが埋め込まれたSpinnerを使用したNullPointerException
private void showUploadDialog(){
Dialog dialog = new Dialog(MyClass.this);
dialog.setContentView(R.layout.uploaddialog);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
final SimpleCursorAdapter dataSource;
final String fields[] = { "siteName","_id" };
int[] to = new int[] { R.id.spinner_site_item };
s = (Spinner) findViewById(R.id.spinner1);
DatabaseHelper helper = new DatabaseHelper(MyClass.this);
database = helper.getWritableDatabase();
Cursor ftpCursor = database.query("ftpsites", fields, null, null, null, null, null);
startManagingCursor(ftpCursor);
if (ftpCursor != null && ftpCursor.moveToFirst()){
dataSource = new SimpleCursorAdapter(this, R.layout.spinner_item, ftpCursor, fields, to);
dataSource.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(dataSource);
} else {
Toast toast = Toast.makeText(getApplicationContext(), "Cursor's fucked up", Toast.LENGTH_SHORT);
toast.show();
}
database.close();
Button button = (Button) dialog.findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
をnullポインタ例外を取得しておきます。ここで
はLogCat出力01-24 15:47:08.198: E/AndroidRuntime(10834): FATAL EXCEPTION: main
01-24 15:47:08.198: E/AndroidRuntime(10834): java.lang.NullPointerException
01-24 15:47:08.198: E/AndroidRuntime(10834): at app.me.myapp.MyClass.showUploadDialog(MyClass.java:257)
01-24 15:47:08.198: E/AndroidRuntime(10834): at app.me.myapp.MyClass.access$15(MyClass.java:233)
01-24 15:47:08.198: E/AndroidRuntime(10834): at app.me.myapp.MyClass$11.onClick(MyClass.java:741)
01-24 15:47:08.198: E/AndroidRuntime(10834): at android.view.View.performClick(View.java:2532)
01-24 15:47:08.198: E/AndroidRuntime(10834): at android.view.View$PerformClick.run(View.java:9293)
01-24 15:47:08.198: E/AndroidRuntime(10834): at android.os.Handler.handleCallback(Handler.java:587)
01-24 15:47:08.198: E/AndroidRuntime(10834): at android.os.Handler.dispatchMessage(Handler.java:92)
01-24 15:47:08.198: E/AndroidRuntime(10834): at android.os.Looper.loop(Looper.java:150)
01-24 15:47:08.198: E/AndroidRuntime(10834): at android.app.ActivityThread.main(ActivityThread.java:4263)
01-24 15:47:08.198: E/AndroidRuntime(10834): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 15:47:08.198: E/AndroidRuntime(10834): at java.lang.reflect.Method.invoke(Method.java:507)
01-24 15:47:08.198: E/AndroidRuntime(10834): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-24 15:47:08.198: E/AndroidRuntime(10834): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-24 15:47:08.198: E/AndroidRuntime(10834): at dalvik.system.NativeStart.main(Native Method)
01-24 15:47:09.559: I/Process(10834): Sending signal. PID: 10834 SIG: 9
あなたは素晴らしいです。ありがとうございました :) – Carnivoris