java - 在 Android Studio 中运行我的代码时出现顶级声明错误
问题描述
我写了这段代码,运行程序时出现错误
期待顶级声明
在关键字extends和其他87个地方附近。它还将诸如 int、float 之类的关键字显示为无法识别。
完整代码:
package com.example.exno1
import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
class MainActivity extends AppCompatActivity{
int ch=1
float font=30
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
finalTextView t= (TextView) findViewById(R.id.textView)
Button b1= (Button) findViewById(R.id.button1)
b1.setOnClickListener(newView.OnClickListener {
@Override
Public void onClick(View v) {
t.setTextSize(font)
font = font + 5
if(font == 50)
font = 30
}
})
Button b2= (Button) findViewById(R.id.button2)
b2.setOnClickListener(newView.OnClickListener {
@Override
public void onClick(View v) {
switch(ch) {
case 1:
t.setTextColor(Color.RED)
break
case 2:
t.setTextColor(Color.GREEN)
break
case 3:
t.setTextColor(Color.BLUE)
break
case 4:
t.setTextColor(Color.CYAN)
break
case 5:
t.setTextColor(Color.YELLOW)
break
case 6:
t.setTextColor(Color.MAGENTA)
break
}
ch++
if(ch == 7)
ch = 1
}
})
}
}
解决方案
它是Java。你忘了分号;
推荐阅读
- vba - VBA宏从一个单元格提取超链接到另一个单元格
- css - CSS 定义的背景图片不显示在 Chrome 中
- javascript - JSON数组到nodejs可读对象流
- node.js - 在 Nodejs(Angular 4,MongoDB)中发布请求时,Req.body 为空
- java - Jackson 的多态性:如果子类型被扩展并显式使用,如何使用 JsonTypeInfo、JsonSubTypes 和 JsonTypeId 注释?
- android - Cordova 和 socket.io :客户端断开和重新连接
- docker - 码头工人未经授权:需要身份验证
- git - 如何在 vagrant VM 中使用 cygwin、git bash 和 git 在 Windows 上设置 git?
- java - 具有不同模式的休眠 @Inheritance(strategy=InheritanceType.JOINED) 会导致错误 (HHH000099)
- python - ValueError: 操作数不能与形状一起广播 (2,3) (998,)