找不到android.graphics,找不到类'android.graphics.drawable.RippleDrawable',无法执行android:onClick,Android Studi...

我正在尝试制作一个订购咖啡的应用程序。(我真的很陌生。)

我的应用程序运行良好,直到出现两个错误。现在,它可以在设备中运行,但是当您尝试触摸按钮时,它将停止。

代码是:

package com.example.android.justjava;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.TextView;

import java.text.NumberFormat;

/**

* This app displays an order form to order coffee.

*/

public class MainActivity extends AppCompatActivity {

int quantity = 0;

//int priceOfOneCup = 5;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

/**

* This method is called when the order button is clicked.

*/

public void submitOrder(View view){

//calculatePrice(quantity, priceOfOneCup);

int price = quantity * 5 ;

String priceMessage = "Total: " + price + "€" + "\nThank You!";

displayMessage(priceMessage);

}

/**

* This method is called when the plus button is clicked.

*/

public void increment(View view) {

quantity = quantity + 1;

displayQuantity(quantity);

}

/**

* This method is called when the minus button is clicked.

*/

public void decrement(View view) {

quantity = quantity - 1;

displayQuantity(quantity);

}

/**

* This method displays the given quantity value on the screen.

*/

private void displayQuantity(int number) {

TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);

quantityTextView.setText(number);

}

/**

* This method displays the given price on the screen.

*/

private void displayPrice(int number) {

TextView priceTextView = (TextView) findViewById(R.id.price_text_view);

priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));

}

/**

* This method displays the given text on the screen.

*/

private void displayMessage(String message) {

TextView priceTextView = (TextView) findViewById(R.id.price_text_view);

priceTextView.setText(message);

}

XML代码:

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="16dp"

tools:context="com.example.android.justjava.MainActivity">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="16dp"

android:text="Quantity"

android:textAllCaps="true" />

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_width="48dp"

android:layout_height="48dp"

android:onClick="decrement"

android:text="-" />

android:id="@+id/quantity_text_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:text="0"

android:textColor="@android:color/black"

android:textSize="16sp"

/>

android:layout_width="48dp"

android:layout_height="48dp"

android:onClick="increment"

android:text="+" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="16dp"

android:layout_marginTop="16dp"

android:text="Price"

android:textAllCaps="true" />

android:id="@+id/price_text_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Total: 0€"

android:textColor="@android:color/black"

android:textSize="16sp" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:onClick="submitOrder"

android:text="Order" />

终端中的第一个错误:

E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering

和主要错误:

E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.example.android.justjava, PID: 32585

java.lang.IllegalStateException: Could not execute method for android:onClick

at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)

at android.view.View.performClick(View.java:4508)

at android.view.View$PerformClick.run(View.java:18675)

at android.os.Handler.handleCallback(Handler.java:733)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:136)

at android.app.ActivityThread.main(ActivityThread.java:5584)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:515)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)

at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.reflect.InvocationTargetException

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:515)

at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)

at android.view.View.performClick(View.java:4508)

at android.view.View$PerformClick.run(View.java:18675)

at android.os.Handler.handleCallback(Handler.java:733)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:136)

at android.app.ActivityThread.main(ActivityThread.java:5584)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:515)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)

at dalvik.system.NativeStart.main(Native Method)

Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1

at android.content.res.Resources.getText(Resources.java:1404)

at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)

at android.widget.TextView.setText(TextView.java:4262)

at com.example.android.justjava.MainActivity.displayQuantity(MainActivity.java:61)

at com.example.android.justjava.MainActivity.increment(MainActivity.java:44)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:515)

at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)

at android.view.View.performClick(View.java:4508)

at android.view.View$PerformClick.run(View.java:18675)

at android.os.Handler.handleCallback(Handler.java:733)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:136)

at android.app.ActivityThread.main(ActivityThread.java:5584)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:515)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)

at dalvik.system.NativeStart.main(Native Method)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你在使用 Android Studio 中进行开发,可以尝试在 `build.gradle` 文件中添加以下依赖项: ``` dependencies { implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.android.support:palette-v7:28.0.0' implementation 'com.android.support:support-vector-drawable:28.0.0' implementation 'com.android.support:animated-vector-drawable:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:support-annotations:28.0.0' implementation 'com.android.support:support-compat:28.0.0' implementation 'com.android.support:support-core-ui:28.0.0' implementation 'com.android.support:support-core-utils:28.0.0' implementation 'com.android.support:support-fragment:28.0.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.google.android.gms:play-services-ads:17.2.1' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.jakewharton:butterknife:10.1.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0' implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' implementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:converter-gson:2.5.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1' implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.afollestad.material-dialogs:core:0.9.6.0' implementation 'com.github.siyamed:android-shape-imageview:0.9.+@aar' implementation 'com.squareup.okhttp3:okhttp:3.12.0' implementation 'com.github.chrisbanes:PhotoView:2.1.3' implementation 'com.google.android:flexbox:1.0.0' implementation 'com.android.support:mediarouter-v7:28.0.0' implementation 'com.android.support:preference-v7:28.0.0' implementation 'com.android.support:exifinterface:28.0.0' implementation 'com.google.android.gms:play-services-maps:16.0.0' implementation 'com.google.android.gms:play-services-auth:16.0.1' implementation 'com.google.android.gms:play-services-location:16.0.0' implementation 'com.google.android.gms:play-services-places:16.0.0' implementation 'com.google.android.gms:play-services-gcm:16.0.0' implementation 'com.google.android.gms:play-services-analytics:16.0.7' implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0' implementation 'com.google.firebase:firebase-core:16.0.8' implementation 'com.google.firebase:firebase-ads:17.2.1' implementation 'com.firebaseui:firebase-ui-auth:4.1.0' implementation 'com.firebaseui:firebase-ui-database:4.1.0' implementation 'com.firebaseui:firebase-ui-storage:4.1.0' implementation 'com.firebaseui:firebase-ui-firestore:4.1.0' implementation 'com.firebaseui:firebase-ui:4.1.0' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9' implementation 'com.google.android.gms:play-services-vision:17.0.2' } ``` 然后,再检查你的 AndroidManifest.xml 文件是否已经声明了相机权限: ``` <uses-feature android:name="android.hardware.camera" android:required="true" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-permission android:name="android.permission.CAMERA" /> ``` 如果还是不到 `android.hardware:camera:2.0`,可以尝试在 SDK Manager 中更新你的 Android SDK。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值