Android应用程序,无法解析两个变量,或者不是字段
packagecom.example.ex03_02;importandroid.app.Activity;importandroid.content.res.Resou...
package com.example.ex03_02;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView myTextView01;
TextView myTextView02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources resources = getBaseContext().getResources();
! Drawable HippoDrawable = resources.getDrawable(R.drawable.darkgray);
myTextView01.setBackground(HippoDrawable);
! myTextView02 = (TextView)findViewById(R.id.myTextView02);
myTextView02.setTextColor(Color.MAGENTA);
}
}
前面有感叹号的两句报错,但是已经在xml文件中实现myTextView02 和
darkgray,为什么没办法导入,Eclipse报错是说“无法解析这两个,或者它们不是字段”
怎么办? 展开
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView myTextView01;
TextView myTextView02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources resources = getBaseContext().getResources();
! Drawable HippoDrawable = resources.getDrawable(R.drawable.darkgray);
myTextView01.setBackground(HippoDrawable);
! myTextView02 = (TextView)findViewById(R.id.myTextView02);
myTextView02.setTextColor(Color.MAGENTA);
}
}
前面有感叹号的两句报错,但是已经在xml文件中实现myTextView02 和
darkgray,为什么没办法导入,Eclipse报错是说“无法解析这两个,或者它们不是字段”
怎么办? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询