I'm at a loss right now. I've tried to run the following class below, and I get an exception in logcat which I can't understand. i don't know more about android studio, but this for my college work.
E/: SECOND ACTIVITY
W/ResourceType: No known package when getting value for resource number 0xffffffff
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dicoding.picodiploma.kedaikopi, PID: 18964
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dicoding.picodiploma.kedaikopi/com.dicoding.picodiploma.kedaikopi.Models.DrinkDetailActivity}: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
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: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:227)
at android.content.res.Resources.getValue(Resources.java:1337)
at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded(ResourceManagerInternal.java:176)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:141)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:132)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:86)
at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:94)
at com.dicoding.picodiploma.kedaikopi.Models.DrinkDetailActivity.onCreate(DrinkDetailActivity.java:77)
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)
I/Process: Sending signal. PID: 18964 SIG: 9
Application terminated.
the debbug message points here imageV.setImageResource (image) ;
. I don't know what needs to be changed
and this is all the code
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.dicoding.picodiploma.kedaikopi.R;
import com.dicoding.picodiploma.kedaikopi.database.SQLiteHelper;
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;
this is code
@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(name, "SECOND ACTIVITY");
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;
}
}
User contributions licensed under CC BY-SA 3.0