我正在尝试使用4个微调器进行布局,这些微调器随着微调器中的每个先前选择而动态变化。一旦填充了所有4个微调器,我将得到一个可用于特定车辆的可用部件列表。
-So,Type,Make,Year(s),Model
我用它作为参考:Dynamic Spinner Using SQLite Database
每当我尝试打开我的应用程序时,应用程序崩溃并且永远不会打开。这是我的LogCat的副本。
10-04 14:22:13.359: D/AndroidRuntime(12825): Shutting down VM
10-04 14:22:13.359: W/dalvikvm(12825): threadid=1: thread exiting with uncaught exception (group=0xb2eb1648)
10-04 14:22:13.369: E/AndroidRuntime(12825): FATAL EXCEPTION: main
10-04 14:22:13.369: E/AndroidRuntime(12825): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lithiumbatteryguide/com.example.lithiumbatteryguide.PowersportsEquivalent}: java.lang.NullPointerException
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.os.Looper.loop(Looper.java:137)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-04 14:22:13.369: E/AndroidRuntime(12825): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 14:22:13.369: E/AndroidRuntime(12825): at java.lang.reflect.Method.invoke(Method.java:525)
10-04 14:22:13.369: E/AndroidRuntime(12825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-04 14:22:13.369: E/AndroidRuntime(12825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-04 14:22:13.369: E/AndroidRuntime(12825): at dalvik.system.NativeStart.main(Native Method)
10-04 14:22:13.369: E/AndroidRuntime(12825): Caused by: java.lang.NullPointerException
10-04 14:22:13.369: E/AndroidRuntime(12825): at com.example.lithiumbatteryguide.DataBaseHelper.getPowersportsType(DataBaseHelper.java:30)
10-04 14:22:13.369: E/AndroidRuntime(12825): at com.example.lithiumbatteryguide.PowersportsEquivalent.onCreate(PowersportsEquivalent.java:26)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.Activity.performCreate(Activity.java:5133)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-04 14:22:13.369: E/AndroidRuntime(12825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-04 14:22:13.369: E/AndroidRuntime(12825): ... 11 more
如果有人需要,我会上传代码。此外,如果有人可以看到我在这个应用程序中做的事情有任何问题,请随时提供帮助(一旦我发布人们需要更多信息的代码)。
这将是我的第一个App,我已经创建了数据库文件。
编辑: 这是我的DataBaseHelper代码:
private static String DB_PATH = "/data/data/com.example.lithiumbatteryguide/databases";
private static String DB_NAME = "powersports.db";
private final int DB_VERSION = 1;
private static SQLiteDatabase myDataBase;
private final Context myContext;
private static final String POWERSPORTS_TABLE = "powersports_data";
private static final String POWERSPORTS_ID = "_id";
static final String POWERSPORTS_TYPE = "powersports_type";
static final String POWERSPORTS_MAKE = "powersports_make";
static final String POWERSPORTS_YEAR = "powersports_year";
static final String POWERSPORTS_MODEL = "powersports_model";
public DataBaseHelper(Context context){
super(context, DB_NAME, null, 1);
this.myContext = context;
}
public static Cursor getPowersportsType(){
return myDataBase.query(POWERSPORTS_TABLE, new String [] {POWERSPORTS_TYPE}, null, null, POWERSPORTS_TYPE, null, null);
}
public static Cursor getPowersportsMake(){
return myDataBase.query(POWERSPORTS_TABLE, new String [] {POWERSPORTS_MAKE}, null, null, POWERSPORTS_MAKE, null, null);
}
public static Cursor getPowersportsYear(){
return myDataBase.query(POWERSPORTS_TABLE, new String [] {POWERSPORTS_YEAR}, null, null, POWERSPORTS_YEAR, null, null);
}
public static Cursor getPowersportsModel(){
return myDataBase.query(POWERSPORTS_TABLE, new String [] {POWERSPORTS_MODEL}, null, null, POWERSPORTS_MODEL, null, null);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + POWERSPORTS_TABLE );
onCreate(db);
}
}
如果需要更多代码,请不要犹豫。
我还没有看到我在写的应用程序中没有做什么。
我注意到我忘了在我的AndroidManifest.xml中添加我的DataBaseHelper类,但现在已经修复但我仍然遇到崩溃错误。我在此文本中包含了更新的LogCat。
10-10 14:39:41.652: E/AndroidRuntime(1917): FATAL EXCEPTION: main
10-10 14:39:41.652: E/AndroidRuntime(1917): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lithiumbatteryguide/com.example.lithiumbatteryguide.PowersportsEquivalent}: java.lang.NullPointerException
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.os.Looper.loop(Looper.java:137)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-10 14:39:41.652: E/AndroidRuntime(1917): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 14:39:41.652: E/AndroidRuntime(1917): at java.lang.reflect.Method.invoke(Method.java:525)
10-10 14:39:41.652: E/AndroidRuntime(1917): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-10 14:39:41.652: E/AndroidRuntime(1917): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-10 14:39:41.652: E/AndroidRuntime(1917): at dalvik.system.NativeStart.main(Native Method)
10-10 14:39:41.652: E/AndroidRuntime(1917): Caused by: java.lang.NullPointerException
10-10 14:39:41.652: E/AndroidRuntime(1917): at com.example.lithiumbatteryguide.DataBaseHelper.getPowersportsType(DataBaseHelper.java:29)
10-10 14:39:41.652: E/AndroidRuntime(1917): at com.example.lithiumbatteryguide.PowersportsEquivalent.onCreate(PowersportsEquivalent.java:27)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.Activity.performCreate(Activity.java:5133)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-10 14:39:41.652: E/AndroidRuntime(1917): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-10 14:39:41.652: E/AndroidRuntime(1917): ... 11 more