我一直在使用 Eclipse 并导入了一个旧项目,但出现以下错误:
R 无法解析为变量
所以我加了:import android.R; 现在我得到了所有这些错误:
main 无法解析或不是字段 theme 无法解析或不是字段 IVDisplay 无法解析或不是字段 IVimage1 无法解析或不是字段 bSetWallpaper 无法解析或不是字段
请让我知道我做错了什么。
爪哇:
package com.vamp6x6x6x.rusty;
import java.io.IOException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
public class rustyactivity extends Activity implements MediaPlayer.OnCompletionListener, View.OnClickListener {
/** Called when the activity is first created. */
ImageView display;
int toPhone;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
Button ending = (Button) findViewById(R.id.theme);
ending.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playSound(R.raw.theme);
}
});
display = (ImageView) findViewById(R.id.IVDisplay);
ImageView image1 = (ImageView) findViewById(R.id.IVimage1);
ImageView image2 = (ImageView) findViewById(R.id.IVimage2);
ImageView image3 = (ImageView) findViewById(R.id.IVimage3);
ImageView image4 = (ImageView) findViewById(R.id.IVimage4);
ImageView image5 = (ImageView) findViewById(R.id.IVimage5);
Button setWall = (Button) findViewById(R.id.bSetWallpaper);
toPhone = R.drawable.guy1;
image1.setOnClickListener(this);
image2.setOnClickListener(this);
image3.setOnClickListener(this);
image4.setOnClickListener(this);
image5.setOnClickListener(this);
setWall.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.IVimage1:
display.setImageResource(R.drawable.guy1);
toPhone = R.drawable.guy1;
break;
case R.id.IVimage2:
display.setImageResource(R.drawable.guy2);
toPhone = R.drawable.guy2;
break;
case R.id.IVimage3:
display.setImageResource(R.drawable.guy3);
toPhone = R.drawable.guy3;
break;
case R.id.IVimage4:
display.setImageResource(R.drawable.guy4);
toPhone = R.drawable.guy4;
break;
case R.id.IVimage5:
display.setImageResource(R.drawable.guy5);
toPhone = R.drawable.guy5;
break;
case R.id.bSetWallpaper:
Bitmap whatever = BitmapFactory.decodeStream(getResources().openRawResource(toPhone));
try{
getApplicationContext().setWallpaper(whatever);
}catch(IOException e){
e.printStackTrace();
}
}
}
private void playSound(int resId) {
MediaPlayer mp = MediaPlayer.create(this, resId);
mp.setOnCompletionListener(this);
mp.start();
}
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
}
}
主要.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.vamp6x6x6x.rusty"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:id="@+id/IVDisplay" android:src="@drawable/guy1" android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center"></ImageView>
<Button android:text="Set Wallpaper" android:id="@+id/bSetWallpaper"
android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
<HorizontalScrollView android:layout_width="250dp" android:layout_height="wrap_content" android:layout_gravity="center">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<ImageView android:id="@+id/IVimage1"
android:src="@drawable/guy1"
android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp"></ImageView>
<ImageView android:id="@+id/IVimage2"
android:src="@drawable/guy2"
android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp"></ImageView>
<ImageView android:id="@+id/IVimage3"
android:src="@drawable/guy3"
android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp"></ImageView>
<ImageView android:id="@+id/IVimage4"
android:src="@drawable/guy4"
android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp"></ImageView>
<ImageView android:id="@+id/IVimage5"
android:src="@drawable/guy5"
android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp"></ImageView>
</LinearLayout>
</HorizontalScrollView>
<Button android:layout_width="wrap_content" android:layout_gravity="center" android:id="@+id/theme" android:layout_height="wrap_content" android:text="Big Guy and Rusty the Boy Robot"></Button>
</LinearLayout>