我收到錯誤,當我運行該項目。我從我的java文件和gradle控制檯附加代碼 這裏是代碼形式activity_funfacts.xml。有一個RelativeLayout標記這裏錯誤:無法找到符號變量relativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".FunFactsMyActivity"
android:background="#ff51b46d">
<TextView
android:text="Did you know"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dp"
android:textColor="#80ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aint strech it when they wake up in the morning"
android:id="@+id/factTextView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="24dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Another Fun Fact"
android:id="@+id/showFactbButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/white" />
</RelativeLayout>
輸出從搖籃控制檯
Executing tasks: [:app:assembleDebug]
Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava
/Users/AndroidStudioProjects/FunFacts/app/src/main/java/com/example/funfacts/FunFactsMyActivity.java:29: error: cannot find symbol
final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
^
symbol: variable relativeLayout
location: class id
1 error
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.252 secs
更多問題而不是答案? – Blackbelt
@Blackbelt:真的,改進的答案。 – Knossos
@Knossos:我在哪裏可以找到R.layout.activity_funfacts? –