gpt4 book ai didi

android - R.layout.main 无法解析为变量

转载 作者:行者123 更新时间:2023-11-29 00:36:24 25 4
gpt4 key购买 nike

我从 Raghav Sood 的 Pro Android 增强现实一书中找到了这段代码。我试过执行书中写的代码,但我遇到了很多困难。我试过清理和构建项目。将复选框勾选在项目的属性对话框中。检查我的代码中是否存在 import Android.R。甚至我卸载了我的 AndroidSDK 并使用不同的 Android 版本和 API 集重新安装它。卸载并重新安装 Eclipse。

这是我的 ProAndroidAR3Activity.java 文件

    package com.paar.ch3widgetoverlay;

import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.TextView;

public class ProAndroidAR3Activity extends Activity{
SurfaceView cameraPreview;
SurfaceHolder previewHolder;
Camera camera;
boolean inPreview;

final static String TAG = "PAAR";
SensorManager sensorManager;

int orientationSensor;
float headingAngle;
float pitchAngle;
float rollAngle;

int accelerometerSensor;
float xAxis;
float yAxis;
float zAxis;

LocationManager locationManager;
double latitude;
double longitude;
double altitude;

TextView xAxisValue;
TextView yAxisValue;
TextView zAxisValue;
TextView headingValue;
TextView pitchValue;
TextView rollValue;
TextView altitudeValue;
TextView latitudeValue;
TextView longitudeValue;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //here is the problem. every part of the code with R. is having problem


locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 2, locationListener);

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
orientationSensor = Sensor.TYPE_ORIENTATION;
accelerometerSensor = Sensor.TYPE_ACCELEROMETER;
sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(orientationSensor), SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(accelerometerSensor), SensorManager.SENSOR_DELAY_NORMAL);

inPreview = false;

cameraPreview = (SurfaceView)findViewById(R.id.cameraPreview);
previewHolder = cameraPreview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

xAxisValue = (TextView) findViewById(R.id.xAxisValue);
yAxisValue = (TextView) findViewById(R.id.yAxisValue);
zAxisValue = (TextView) findViewById(R.id.zAxisValue);
headingValue = (TextView) findViewById(R.id.headingValue);
pitchValue = (TextView) findViewById(R.id.pitchValue);
rollValue = (TextView) findViewById(R.id.rollValue);
altitudeValue = (TextView) findViewById(R.id.altitudeValue);
longitudeValue = (TextView) findViewById(R.id.longitudeValue);
latitudeValue = (TextView) findViewById(R.id.latitudeValue);

这是我的项目的 AndroidManifest.xml 文件:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.paar.ch3widgetoverlay"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".ProAndroidAR3Activity"
android:screenOrientation = "landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges = "keyboardHidden|orientation">
<intent-filter >
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>

下面是res/layout/main.xml文件

    <RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="@+id/cameraPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

<TextView
android:id="@+id/xAxisLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="15dp"
android:text="@string/xAxis" />

<TextView
android:id="@+id/yAxisLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/xAxisLabel"
android:layout_below="@+id/xAxisLabel"
android:text="@string/yAxis" />

<TextView
android:id="@+id/zAxisLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/yAxisLabel"
android:layout_below="@+id/yAxisLabel"
android:text="@string/zAxis" />

<TextView
android:id="@+id/headingLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/zAxisLabel"
android:layout_below="@+id/zAxisLabel"
android:layout_marginTop="19dp"
android:text="@string/heading" />

<TextView
android:id="@+id/pitchLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/headingLabel"
android:layout_below="@+id/headingLabel"
android:text="@string/pitch" />

<TextView
android:id="@+id/rollLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/pitchLabel"
android:layout_below="@+id/pitchLabel"
android:text="@string/roll" />

<TextView
android:id="@+id/latitudeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/rollLabel"
android:layout_below="@+id/rollLabel"
android:layout_marginTop="34dp"
android:text="@string/latitude" />

<TextView
android:id="@+id/longitudeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/latitudeLabel"
android:layout_below="@+id/latitudeLabel"
android:text="@string/longitude" />

<TextView
android:id="@+id/altitudeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/longitudeLabel"
android:layout_below="@+id/longitudeLabel"
android:text="@string/altitude" />

<TextView
android:id="@+id/xAxisValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/xAxisLabel"
android:layout_marginLeft="56dp"
android:layout_toRightOf="@+id/longitudeLabel"
android:text="@string/empty" />

<TextView
android:id="@+id/yAxisValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/yAxisLabel"
android:layout_alignBottom="@+id/yAxisLabel"
android:layout_alignLeft="@+id/xAxisValue"
android:text="@string/empty" />

<TextView
android:id="@+id/zAxisValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/headingLabel"
android:layout_alignLeft="@+id/yAxisValue"
android:text="@string/empty" />

<TextView
android:id="@+id/headingValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/headingLabel"
android:layout_alignBottom="@+id/headingLabel"
android:layout_alignLeft="@+id/zAxisValue"
android:text="@string/empty" />

<TextView
android:id="@+id/pitchValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/pitchLabel"
android:layout_alignBottom="@+id/pitchLabel"
android:layout_alignLeft="@+id/headingValue"
android:text="@string/empty" />

<TextView
android:id="@+id/rollValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/latitudeLabel"
android:layout_alignLeft="@+id/pitchValue"
android:text="@string/empty" />

<TextView
android:id="@+id/latitudeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/latitudeLabel"
android:layout_alignLeft="@+id/rollValue"
android:text="@string/empty" />

<TextView
android:id="@+id/longitudeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/longitudeLabel"
android:layout_alignBottom="@+id/longitudeLabel"
android:layout_alignLeft="@+id/latitudeValue"
android:text="@string/empty" />

<TextView
android:id="@+id/altitudeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/altitudeLabel"
android:layout_alignBottom="@+id/altitudeLabel"
android:layout_alignLeft="@+id/longitudeValue"
android:text="@string/empty" />

</RelativeLayout>`

下面是res/values/strings.xml文件

    <?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, ProAndroidAR3Activity!</string>
<string name="app_name">Pro Android AR 3 Widget Overlay</string>
<string name="xAxis">X Axis:</string>
<string name="yAxis">Y Axis:</string>
<string name="zAxis">Z Axis:</string>
<string name="heading">Heading:</string>
<string name="pitch">Pitch:</string>
<string name="roll">Roll:</string>
<string name="altitude">Altitude:</string>
<string name="longitude">Longitude:</string>
<string name="latitude">Latitude:</string>
<string name="empty"></string>
</resources>

我已将 minsdk 版本设置为 2.1,即 API 7,编译 SDK 版本为 4.1,即 API 16...

请帮帮我...

最佳答案

您是否在 Eclipse (/gen/[yourpackage]/R.java) 的“gen”文件夹下正确生成了新的 R.java 类?如果它与您的 Activity 在同一个包中,则无需手动导入!

如果 XML 正确,它应该在那里!如果 XML 中存在语法错误,则 Eclipse 将不会生成 R.java。

请问,您的布局文件末尾有一个奇怪的 '`' 字符,我不知道这是否是您帖子中的意外,但这可能是个问题:

</RelativeLayout>`

希望对您有所帮助!

关于android - R.layout.main 无法解析为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12465332/

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