我的 Java 简单按钮应用程序无法运行,显示不兼容的版本 v7
My Java program for simple button app is not working showing incompatible version v7
我是 android 开发新手,开始学习 udacity 课程,但 java 代码不是 运行 它显示错误(下图)。我是 stack overflow 的新手,很抱歉我不知道如何正确 post 一个问题。
java程序(错误可知图片)
https://drive.google.com/file/d/1D-OSZX2oxuRWZD_Yb8x4WWUBhMykWQKq/view?usp=sharing
package com.example.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
@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) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}`
XML 代码`
<RelativeLayout 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"
tools:context=".MainActivity">
<TextView
android:id="@+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantity:"
android:padding="15dp"
/>
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_below="@id/quantity"
android:paddingLeft="30dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_below="@id/quantity_text_view"
android:onClick="submitOrder"
android:text="Order"/>
</RelativeLayout>`
enter image description here
v7 不再受支持。而不是 v7 使用 androidx 包。
import androidx.appcompat.app.AppCompatActivity;
我是 android 开发新手,开始学习 udacity 课程,但 java 代码不是 运行 它显示错误(下图)。我是 stack overflow 的新手,很抱歉我不知道如何正确 post 一个问题。
java程序(错误可知图片)
https://drive.google.com/file/d/1D-OSZX2oxuRWZD_Yb8x4WWUBhMykWQKq/view?usp=sharing
package com.example.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
@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) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}`
XML 代码`
<RelativeLayout 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"
tools:context=".MainActivity">
<TextView
android:id="@+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantity:"
android:padding="15dp"
/>
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_below="@id/quantity"
android:paddingLeft="30dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_below="@id/quantity_text_view"
android:onClick="submitOrder"
android:text="Order"/>
</RelativeLayout>`
enter image description here
v7 不再受支持。而不是 v7 使用 androidx 包。
import androidx.appcompat.app.AppCompatActivity;