我刚刚开始在Android Studio中编程,我发生了一个错误,上面写着:"无法解析符号''",我在google和Stack上查找了溢出,无法找到解决我的问题的解决方案。 我已经看到很多事情说我需要进口东西或清洁和建造,但是当我尝试它 - 它对我没有帮助时,如果有人可以向我解释这个因为也许我做某事会有所帮助错误的尝试解决它......
这是我的代码:
.Java文件:
package com.example.android.courtcounter;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int scoreA=0,scoreB=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void displayForTeamA(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_score);
scoreView.setText(String.valueOf(score));
}
public void displayForTeamB(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_b_score);
scoreView.setText(String.valueOf(score));
}
public void addThreeForTeamA(View v)
{
scoreA+=3;
displayForTeamA(scoreA);
}
public void addTwoForTeamA(View v)
{
scoreA+=2;
displayForTeamA(scoreA);
}
public void addOneForTeamA(View v)
{
scoreA+=1;
displayForTeamA(scoreA);
}
public void addThreeForTeamB(View v)
{
scoreB+=3;
displayForTeamB(scoreB);
}
public void addTwoForTeamB(View v)
{
scoreB+=2;
displayForTeamB(scoreB);
}
public void addOneForTeamB(View v)
{
scoreB+=1;
displayForTeamB(scoreB);
}
public void setToZero(View v)
{
scoreA=0;
scoreB=0;
displayForTeamA(scoreA);
displayForTeamB(scoreB);
}
}
.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
android:orientation="horizontal"
tools:showIn="@layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team A"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:padding="4dp"
android:textSize="14sp"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"/>
<TextView
android:id="@+id/team_a_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="56dp"
android:textColor="#000000"
android:fontFamily="sans-serif-light"
android:layout_marginTop="20sp"
android:layout_gravity="center_horizontal"
android:padding="4dp"
android:layout_marginBottom="24dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+3 Points"
android:layout_marginTop="30sp"
android:onClick="addThreeForTeamA"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp"
android:layout_marginBottom="8dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+2 Points"
android:layout_marginTop="20sp"
android:onClick="addTwoForTeamA"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp"
android:layout_marginBottom="8dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Free Throw"
android:layout_marginTop="20sp"
android:onClick="addOneForTeamA"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp"/>
</LinearLayout>
<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/darker_gray">
</view>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team B"
android:layout_gravity="center_horizontal"
android:padding="4dp"
android:textSize="14sp"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/team_b_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="56dp"
android:textColor="#000000"
android:fontFamily="sans-serif-light"
android:layout_marginTop="20sp"
android:layout_gravity="center_horizontal"
android:padding="4dp"
android:layout_marginBottom="24dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+3 Points"
android:layout_marginTop="30sp"
android:onClick="addThreeForTeamB"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp"
android:layout_marginBottom="8dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+2 Points"
android:layout_marginTop="20sp"
android:onClick="addTwoForTeamB"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp"
android:layout_marginBottom="8dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Free Throw"
android:layout_marginTop="20sp"
android:onClick="addOneForTeamB"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="setToZero"/>
</RelativeLayout>
任何帮助都会受到关注:)
答案 0 :(得分:0)
清理您的项目。如果它不关闭项目并删除.gradle并重新打开项目
,这可能会有所帮助答案 1 :(得分:0)
通常此错误是由Gradle版本不兼容引起的。将鼠标悬停在当前版本上并单击“更新”,以更新您的gradle版本。然后清理并重建您的项目。应该这样做。