在.java代码上未检测到我在布局.xml上添加的任何组件。 我是一个绝对的初学者,尝试遵循本教程:https://www.androidauthority.com/lets-build-a-simple-text-editor-for-android-773774/
所以,这一定是真的很愚蠢的哈哈
我尝试过:重新启动android studio ,清理项目,重建项目,使缓存无效 ,重新导入项目,删除.iml文件和.idea文件夹。
我的代码...除了变量名外,它必须与本教程中的代码几乎相同,但是在这里:
MainActivity.java
package com.example.notezinhas;
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 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = 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);
}
String ff = some_textView;
}
^最后一行是Cannot resolve symbol 'some_textView'
出现的地方
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/some_textView"
layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:showIn="@layout/activity_main">
<TextView
android:id="@+id/some_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
日志猫!
2019-04-03 23:52:33.075 9866-9992/? E/TransactionsProtoFiller: Client token done future failed
java.util.concurrent.ExecutionException: java.lang.Throwable: Account is null
at com.google.common.r.a.d.b(SourceFile:107)
at com.google.common.r.a.d.get(SourceFile:81)
at com.google.common.r.a.da.a(SourceFile:1)
at com.google.common.r.a.bf.a(SourceFile:28)
at com.google.android.apps.gsa.search.core.google.e.a.b(SourceFile:18)
at com.google.android.apps.gsa.search.core.google.e.a.a(SourceFile:8)
at com.google.android.apps.gsa.staticplugins.h.a.a(SourceFile:81)
at com.google.android.apps.gsa.staticplugins.h.b.c.a(Unknown Source:8)
at com.google.android.libraries.gsa.n.a.d.a(Unknown Source:2)
at com.google.common.r.a.cx.b(SourceFile:9)
at com.google.common.r.a.bs.run(SourceFile:5)
at com.google.common.r.a.cw.run(SourceFile:7)
at com.google.android.apps.gsa.shared.util.c.b.g.run(Unknown Source:3)
at com.google.android.apps.gsa.shared.util.c.b.be.run(SourceFile:3)
at com.google.android.apps.gsa.shared.util.c.b.be.run(SourceFile:3)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:914)
at com.google.android.apps.gsa.shared.util.c.b.l.run(SourceFile:6)
Caused by: java.lang.Throwable: Account is null
at com.google.android.apps.gsa.staticplugins.fl.d.a(SourceFile:6)
at com.google.android.apps.gsa.search.core.google.e.a.b(SourceFile:16)
at com.google.android.apps.gsa.search.core.google.e.a.a(SourceFile:8)
at com.google.android.apps.gsa.staticplugins.h.a.a(SourceFile:81)
at com.google.android.apps.gsa.staticplugins.h.b.c.a(Unknown Source:8)
at com.google.android.libraries.gsa.n.a.d.a(Unknown Source:2)
at com.google.common.r.a.cx.b(SourceFile:9)
at com.google.common.r.a.bs.run(SourceFile:5)
at com.google.common.r.a.cw.run(SourceFile:7)
at com.google.android.apps.gsa.shared.util.c.b.g.run(Unknown Source:3)
at com.google.android.apps.gsa.shared.util.c.b.be.run(SourceFile:3)
at com.google.android.apps.gsa.shared.util.c.b.be.run(SourceFile:3)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:914)
at com.google.android.apps.gsa.shared.util.c.b.l.run(SourceFile:6)
您以前看过这个问题吗?我该怎么办?
答案 0 :(得分:0)
-_-对于任何可能看到此内容的人:
setContentView(R.layout.activity_main);
之后访问组件(在这种情况下,我试图将其移到mainActivity类的方法之外)我为使其正常运行所做的其他事情: