1

主.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        
    }
 }

主要的.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>

安卓清单

<?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>`

我一直试图解决这个问题好几天了,所以任何帮助将不胜感激

4

1 回答 1

2

消除

import android.R;

Main.java. 不知何故,错误R被导入了。

如果之后无法解决R,请确保导入的版本是:

import com.example.lolo.R;
于 2013-06-30T10:04:54.360 回答