package com.example.android.favoritetoys;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// TODO (1) Declare a TextView variable called mToysListTextView
TextView mToysListTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToysListTextView = (TextView).findViewById(R.id.tv_toy_names);
// TODO (3) Use findViewById to get a reference to the TextView from the layout
// TODO (4) Use the static ToyBox.getToyNames method and store the names in a String array
String[] toyNames = ToyBox.getToyNames();
// TODO (5) Loop through each toy and append the name to the TextView (add \n for spacing)
for (String toyName : toyNames) {
mToysListTextView.append(toyName + "\n\n\n");
}发布于 2017-06-29 22:32:43
转到您的build.gradle文件。在那里你可以找到下面给出的代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "com.android.example.favoritetoys"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
}你需要做的就是根据你的“构建工具版本”把它改成buildToolsVersion '25.0.2‘。我正在使用strong textbuildToolsVersion '25.0.1‘
发布于 2017-04-26 05:58:48
您需要导入最后一个类,只需添加
import android.widget.TextView;https://stackoverflow.com/questions/42406981
复制相似问题