Main.java
package com.example.lolo;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Main extends Activity{
TextView symbolOut;
TextView priceOut;
TextView changePercentageOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);`
//It says that "main could not be resolved or is not in a field
symbolOut = (TextView) findViewById(R.id.stockPriceOutput);`
//t also says that stockPriceOutput cannot be resolved or is not in a field
}
}
main.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Splash" >
<Button
android:id="@+id/get_quote_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Get Quote" />
<TextView
android:id="@+id/stockSymbolOutput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/get_quote_button"
android:layout_below="@+id/stockPriceOutput"
android:layout_marginTop="86dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/stockPriceOutput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/get_quote_button"
android:layout_below="@+id/get_quote_button"
android:layout_marginTop="18dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/stockChangePercentageOutput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/stockSymbolOutput"
android:layout_alignParentBottom="true"
android:layout_marginBottom="92dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lolo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.lolo.Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="@string/app_name" android:name=".Main"></activity>
</application>
</manifest>`
我一直在努力解决这个问题,所以任何帮助都会非常感激
答案 0 :(得分:2)
删除
import android.R;
来自Main.java
。不知怎的,导入了错误的R
。
如果之后无法解析R
,请确保导入的版本为:
import com.example.lolo.R;