java.lang.NumberFormatException:null(Android Studio中的错误)



我在下面得到了这个错误。我正在从firebasesqlite浏览器检索我的数据库。希望你们能帮我解决这个问题。

提前谢谢!

这是我的数据库.java:

public class Database extends SQLiteAssetHelper {
private static final String DB_NAME="coolblogDB.db";
private static final int DB_VER=1;

public Database(Context context) { super(context, DB_NAME, null, DB_VER); }
public List<Order> getCarts() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String[] sqlSelect = {"ProductId", "ProductName", "Quantity", "Price", "Discount"};
String sqlTable = "OrderDetail";
qb.setTables(sqlTable);
Cursor c = qb.query(db, sqlSelect, null, null, null, null, null);
final List<Order> result = new ArrayList<>();
if (c.moveToFirst()) {
do {
result.add(new Order(c.getString(c.getColumnIndex("ProductId")),
c.getString(c.getColumnIndex("ProductName")),
c.getString(c.getColumnIndex("Quantity")),
c.getString(c.getColumnIndex("Price")),
c.getString(c.getColumnIndex("Discount"))
));
} while (c.moveToNext());
}
return result;
}
public void addToCart(Order order)
{
SQLiteDatabase db = getReadableDatabase();
String query = String.format("INSERT INTO OrderDetail(ProductId,ProductName,Quantity,Price,Discount) VALUES('%s','%s','%s','%s','%s');",
order.getProductId(),
order.getProductName(),
order.getQuantity(),
order.getPrice(),
order.getDiscount());
db.execSQL(query);
}
public void cleanCart()
{
SQLiteDatabase db = getReadableDatabase();
String query = String.format("DELETE FROM OrderDetail");
db.execSQL(query);
}
}

这是我的logcat:

10-15 13:48:34.439 12860-12860/com.example.mariamsyafiqah.coolblog2E/AndroidRuntime:致命异常:main流程:com.example.mariamsyafiqah.coolblog2,PID:12860java.lang.RuntimeException:无法启动活动组件信息{com.example.mariamsyafiqah.coolblog2/com.example.maliamsyafikah.coolbog2.Cart}:java.lang.NumberFormatException:null在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)在android.app.ActivityThread.handleLaunchActivity(ActivityThreads.java:2726)在android.app.ActivityThread.-wrap12(ActivityThreads.java)在android.app.ActivityThread$H.handleMessage(ActivityThreads.java:1477)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper.loop(Looper.java:154)在android.app.ActivityThread.main(ActivityThreads.java:6119)位于java.lang.reflect.Method.ioke(本机方法)在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)网址:com.android.internal.os.ZygoteInit.main(ZygoteNit.java:776)导致原因:java.lang.NumberFormatException:null位于java.lang.Integer.parseInt(Integer.java:483)位于java.lang.Integer.parseInt(Integer.java:556)在com.example.mariamsyafiqah.coolblog2.Cart.loadListDrink(Cart.java:128)网址:com.example.mariamsyafiqah.coolblog2.Cart.onCreate(Cart.java:71)在android.app.Activity.performCreate(Activity.java:6679)在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)在android.app.ActivityThread.handleLaunchActivity(ActivityThreads.java:2726)在android.app.ActivityThread.-wrap12(ActivityThreads.java)在android.app.ActivityThread$H.handleMessage(ActivityThreads.java:1477)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper.loop(Looper.java:154)在android.app.ActivityThread.main(ActivityThreads.java:6119)位于java.lang.reflect.Method.ioke(本机方法)在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)网址:com.android.internal.os.ZygoteInit.main(ZygoteNit.java:776)

检查Cart.java第128行,如下错误所示:

java.lang.NumberFormatException:在的java.lang.Integer.parseInt(Integer.java:483)的java.lang.Integer.parseInt(Integer.java:556)处为null。example.mariamsyafiqah.coolblog2.Cart.loadListDrink(Cart.java:128)

有一行类似于以下内容:

int val = Integer.parseInt(stringValue);

如果您的stringValue为null或为空,则会引发错误。你需要检查字符串是否是正确的数字或不是第一个

相关内容

  • 没有找到相关文章

最新更新