微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的简单按钮应用程序的Java程序无法正常显示v7版本

如何解决我的简单按钮应用程序的Java程序无法正常显示v7版本

我是android开发人员的新手,开始从udacity课程学习,但是Java代码未运行它显示错误(下图)。我是堆栈溢出的新手,太抱歉了,我不知道如何正确地发布问题。

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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。