这没有任何意义,我收到一个错误,说setOnClickListener不能应用于MainActivity.但我做了其他项目,我从来没有遇到过这个问题.这是怎么回事?
public class MainActivity extends ActionBarActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = ((Button) findViewById(R.id.button));
button.setOnClickListener(this);
}
Run Code Online (Sandbox Code Playgroud) 当我运行我的程序时,我没有遇到任何问题.当我尝试生成签名的apk时,我被告知getDefaultProguardFile无法解析.我怎样才能解决这个问题.这是代码.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.dose.apps.brainnoodles"
minSdkVersion 8
targetSdkVersion 21
versionCode 13
versionName "2.13"
}
buildTypes {
release {
//apply plugin: 'idea'
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/InMobi-4.5.3.jar')
}
Run Code Online (Sandbox Code Playgroud)
这是被问到的堆栈跟踪
Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'void setTraversalAfter(android.view.View,int)' in library class android.view.accessibility.AccessibilityNodeInfo
Warning:android.support.v4.media.session.MediaSessionCompatApi22: can't find referenced method 'void setRatingType(int)' in library class android.media.session.MediaSession
Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'android.view.accessibility.AccessibilityNodeInfo getTraversalBefore()' …Run Code Online (Sandbox Code Playgroud) 我正在尝试增加一个乒乓球游戏框架.我希望每次球与球拍接触时球的大小都会增加.
这是我的尝试.第一个代码块是我认为问题所在.第二个街区是全班.
public class PlayState extends State {
private Paddle paddleRight, paddleLeft;
private static final int PADDLE_WIDTH = 30;
private static final int PADDLE_HEIGHT = 60;
private Ball ball;
//bDiam stands for ball diameter
private static int bDiam = 10;
private int playerScore = 0;
private Font scoreFont;
@Override
public void init() {
paddleLeft = new Paddle(0, 195, PADDLE_WIDTH, PADDLE_HEIGHT);
paddleRight = new Paddle(785, 195, PADDLE_WIDTH, PADDLE_HEIGHT);
scoreFont = new Font("SansSerif", Font.BOLD, 25);
ball = new Ball(300, 200, bDiam, bDiam); …Run Code Online (Sandbox Code Playgroud) 这是一本书中的练习代码,我正在学习try/catch语句.
显示的第一种方法要求load方法检索两个图像.此代码中的错误是资源文件中第一个img的名称称为"welcome.png",但正如您所看到的,它显示为"welcomee.png"(欢迎结束时的额外e).当我运行代码时,它不会打印出catch语句中的代码.它确实显示了堆栈跟踪(因为无论如何都会这样做),但它不会打印出"读取时出错:文件名".为什么是这样?
public class Resources {
public static BufferedImage welcome, iconimage;
public static void load() {
welcome = loadImage("welcomee.png");
iconimage = loadImage("iconimage.png");
}
private static AudioClip loadSound(String filename) {
URL fileURL = Resources.class.getResource("/resources/" + filename);
return Applet.newAudioClip(fileURL);
}
private static BufferedImage loadImage(String filename) {
BufferedImage img = null;
try {
img = ImageIO.read(Resources.class.getResourceAsStream("/resources/" + filename));
} catch (IOException e) {
System.out.println("Error while reading: " + filename);
e.printStackTrace();
}
return img;
}
}
Run Code Online (Sandbox Code Playgroud)