Java 我的应用程序崩溃了。不幸的是,应用程序已停止
我是一名新的Android开发者,在Udacity初学者课程上开发JustJava应用程序。使用手机调试代码,当我点击按钮更新价格时,会出现错误:“不幸的是,JustJava已经停止” AndroidManifest.xmlJava 我的应用程序崩溃了。不幸的是,应用程序已停止,java,android,xml,Java,Android,Xml,我是一名新的Android开发者,在Udacity初学者课程上开发JustJava应用程序。使用手机调试代码,当我点击按钮更新价格时,会出现错误:“不幸的是,JustJava已经停止” AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ex
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.justjava">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="justjava"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.justjava.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="quantity"
android:textAllCaps="true"
android:padding="16dp" />
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="@android:color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAllCaps="true"
android:padding="16dp" />
<TextView
android:id="@+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NGN0"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="@android:color/black"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDER"
android:layout_margin="16dp"
android:onClick="submitOrder"/>
</LinearLayout>
活动\u main.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.justjava">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="justjava"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.justjava.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="quantity"
android:textAllCaps="true"
android:padding="16dp" />
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="@android:color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAllCaps="true"
android:padding="16dp" />
<TextView
android:id="@+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NGN0"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="@android:color/black"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDER"
android:layout_margin="16dp"
android:onClick="submitOrder"/>
</LinearLayout>
错误相当具体。根本原因在stacktrace的末尾:
Caused by: java.lang.NoClassDefFoundError: android.icu.text.NumberFormat
at com.example.android.justjava.MainActivity.displayPrice(MainActivity.java:49)
at com.example.android.justjava.MainActivity.submitOrder(MainActivity.java:33)
类加载器可能找不到您在应用程序中使用的android.icu.text.NumberFormat
类定义。您应该检查手机上安装的Android版本是否与该类兼容,该类仅在API 24(Android 7.0)之后才可用
错误相当具体。根本原因在stacktrace的末尾:
Caused by: java.lang.NoClassDefFoundError: android.icu.text.NumberFormat
at com.example.android.justjava.MainActivity.displayPrice(MainActivity.java:49)
at com.example.android.justjava.MainActivity.submitOrder(MainActivity.java:33)
类加载器可能找不到您在应用程序中使用的android.icu.text.NumberFormat
类定义。您应该检查手机上安装的Android版本是否与该类兼容,该类仅在API 24(Android 7.0)之后才可用
您在哪里调用这些方法?您是否尝试过在Android emulator中运行这些方法?您的设备似乎不知道什么是
android.icu.text.NumberFormat
。您可以从堆栈跟踪中看到:java.lang.NoClassDefFoundError:android.icu.text.NumberFormat
。根据文档,这只是在API级别24中添加的:好的。我“我会试试仿真器。感谢@davidxxx更改导入android.icu.text.NumberFormat类顶部的code>语句以导入java.text.NumberFormat代码>。你刚买错了。太棒了!!!我的应用程序现在运行。非常感谢。你是炸弹。你在哪里调用这些方法?你试过在Android模拟器上运行这个吗?您的设备似乎不知道什么是android.icu.text.NumberFormat
。您可以从堆栈跟踪中看到:java.lang.NoClassDefFoundError:android.icu.text.NumberFormat
。根据文档,这只是在API级别24中添加的:好的。我“我会试试仿真器。感谢@davidxxx更改导入android.icu.text.NumberFormat类顶部的code>语句以导入java.text.NumberFormat代码>。你刚买错了。太棒了!!!我的应用程序现在运行。非常感谢。你就是炸弹。可以我用的是安卓4.4版本的GioneeM3手机。我能把它升级到安卓7.0吗?对不起,不知道。你现在可以用模拟器来做。哇。可以我用的是安卓4.4版本的GioneeM3手机。我能把它升级到安卓7.0吗?对不起,不知道。您现在可以使用模拟器来完成这项工作。