gpt4 book ai didi

android - 错误: Cannot find symbol variable

转载 作者:行者123 更新时间:2023-12-02 10:54:03 24 4
gpt4 key购买 nike

我看了这个家伙的教程:
https://www.youtube.com/watch?v=-SUvA1fXaKw

最后(大约9:55),他写下了:

if(fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_main, fragment);
ft.commit();

我在activity_main_menu1_start_seite中重命名了content_main,我以为可以将content_main替​​换为activity_main_menu1_start_seite,但是随后它说“找不到符号变量activity_main_menu1_start_seite”

也许您需要我的整个代码。
我将错误标记为“Blockquote”。
抱歉任何问题(我是这个网站的新手)
package com.d_and_d_studios.test3;
import android.Manifest;
import android.app.Fragment;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import at.markushi.ui.CircleButton;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

CircleButton btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_drawer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

btn = (CircleButton) findViewById(R.id.circleButton);
}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

//Brauche ich vielleicht doch noch irgendwann!
//@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);
//}

private void displaySelectedScreen(int id) {
Fragment fragment = null;

switch (id) {
case R.id.nav_powersavingmode:
fragment = new Menu_2_Energiesparmodus();
break;
case R.id.nav_feedback:
fragment = new Menu_3_Bewerte_die_App();
break;
case R.id.nav_send:
fragment = new Menu_4_Teile_uns_Fehler_mit();

}

if(fragment != null) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.activity_main_menu1_start_seite, fragment); ft.commit(); }


        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}


@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.nav_powersavingmode) {
// Handle the camera action
} else if (id == R.id.nav_feedback) {

} else if (id == R.id.nav_send) {

}

displaySelectedScreen(id);
return true;
}
}
<?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"
android:background="@color/backgroundcolor"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.d_and_d_studios.test3.MainActivity"
tools:showIn="@layout/toolbar_main">

<at.markushi.ui.CircleButton
android:id="@+id/circleButton"
android:layout_width="116dp"
android:layout_height="116dp"
android:layout_centerInParent="true"
android:src="@drawable/ic_power_settings_new_black_24dp"
app:cb_color="#000"
app:cb_pressedRingWidth="20dp"

tools:layout_editor_absoluteY="178dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/menu1_text1"
android:fontFamily="sans-serif"
android:textColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.23" />

</android.support.constraint.ConstraintLayout>

最佳答案

R类是根据项目的res子文件夹中文件的名称和内容生成的。如果Android Studio不能自动执行此操作,则可以通过单击工具栏上的“构建”按钮来强制进行手动构建。

关于android - 错误: Cannot find symbol variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44608476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com