Masalah pada log.e yang mengakibatkan intent tidak dapat di buka pada aplikasi

tidak paham cara memperbaiki masalah di android studio, pada bagian log.e("SECOND ACTIVITY", name);

public class DrinkDetailActivity extends AppCompatActivity {
    private int item = 0;
    private int price = 0;
    TextView sumTextView;
    TextView priceTotalTextView;
    TextView txtName, txtQuantity, txtPrice;
    Button btnAdd, btnCart;
    public static SQLiteHelper sqLiteHelper;

    @Override
        protected void onCreate (Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_detail);

        init();

        sqLiteHelper = new SQLiteHelper(this, "DrinDB.sqlite", null, 1);
        sqLiteHelper.queryData("CREATE TABLE IF NOT EXISTS CART(ID INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, " +
                "quantity INTEGER, price INTEGER)");

        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item < 1) {
                    Toast.makeText(DrinkDetailActivity.this, "Maaf Pesanan Minimal 1 cup", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.i("TXT PRICE", txtName.getText().toString());
                    sqLiteHelper.insertData(txtName.getText().toString().trim(),
                            txtQuantity.getText().toString().trim(),
                            txtPrice.getText().toString().trim());

                    Toast.makeText(getApplicationContext(), "Masuk Keranjang!", Toast.LENGTH_SHORT).show();
                    txtQuantity.setText("0");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        btnCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(DrinkDetailActivity.this, CartListActivity.class);
                startActivity(intent);
            }
        });

        String name = getIntent().getStringExtra("name");
        String type = getIntent().getStringExtra("type");
        int image;
        image = getIntent().getIntExtra("image", -1);
        price = getIntent().getIntExtra("price", -1);
        Log.e("SECOND ACTIVITY", name);

        TextView nameTV = (TextView) findViewById(R.id.drink_name_text_view);
            nameTV.setText(name);
        TextView typeTV = (TextView) findViewById(R.id.type);
            typeTV.setText(type);
        ImageView imageV = (ImageView) findViewById(R.id.drink_image);
            imageV.setImageResource(image);
            imageV.setVisibility(View.VISIBLE);
        TextView priceTV = (TextView) findViewById(R.id.harga_detail_text_view);
            priceTV.setText(Integer.toString(price));

            sumTextView = (TextView) findViewById(R.id.sum_text_view);
            priceTotalTextView =(TextView) findViewById(R.id.harga_total_text_view);
            Button incrementBtn = (Button) findViewById(R.id.increment_btn);
            incrementBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    increment();
                }
            });
            Button decrementBtn = (Button) findViewById(R.id.decrement_btn);
            decrementBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    decrement();
                }
            });
    }

    private void init(){
        txtName = findViewById(R.id.drink_name_text_view);
        txtQuantity = findViewById(R.id.sum_text_view);
        txtPrice = findViewById(R.id.harga_total_text_view);
        btnAdd = findViewById(R.id.pesan_btn);
        btnCart = findViewById(R.id.cart_btn);
    }
    private void  increment(){
        item++;
        sumTextView.setText(Integer.toString(item));
        priceTotalTextView.setText(Integer.toString(sumOfProduct(price)));
    }
    private void decrement(){
        if(item<1){
            Toast.makeText(this, "maaf Anda tidak dapat memesan kurang dari 1", Toast.LENGTH_SHORT).show();
            return;
        }
        item =item-1;
        sumTextView.setText(Integer.toString(item));
        priceTotalTextView.setText(Integer.toString(sumOfProduct(price)));
    }
    private int sumOfProduct(int price){
        return item * price;
    }
}

dan ini error messagenya at com.dicoding.picodiploma.kedaikopi.Models.DrinkDetailActivity.onCreate(DrinkDetailActivity.java:69)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2760)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2821)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:181)
        at android.app.ActivityThread.main(ActivityThread.java:6295)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:793)
     Caused by: java.lang.NullPointerException: println needs a message
        at android.util.Log.println_native(Native Method)
        at android.util.Log.e(Log.java:236)
        at com.dicoding.picodiploma.kedaikopi.Models.DrinkDetailActivity.onCreate(DrinkDetailActivity.java:69)
        at android.app.Activity.performCreate(Activity.java:6834)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2713)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2821)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:181)
        at android.app.ActivityThread.main(ActivityThread.java:6295)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:793)

avatar aditya178
@aditya178

1 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

2 Jawaban:

coba dicek mungkin nama dari string extra-nya typo

avatar arkaanni
@arkaanni

29 Kontribusi 15 Poin

Dipost 4 tahun yang lalu

<pre> Caused by: java.lang.NullPointerException: println needs a message </pre>

untuk ada yg null, nilainya bro.

DrinkDetailActivity baris 69 apa codenya?

avatar IfanZalukhu
@IfanZalukhu

217 Kontribusi 158 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban