1
Main.java我不能把我的ID從我的main.xml文件到我的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清單
<?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>`
我一直試圖弄清楚這幾天,所以任何幫助將不勝感激
非常感謝你肯!你是一個拯救生命的人。 – LaurentL