有人可以弄清楚为什么我得到 R is notsolved to a variable error。我查看了与我现在提出的问题类似的其他问题,但找不到任何适合我的解决方案。
主要活动
package com.example.stressanalysis;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
public class main_activity extends Activity {
private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
Button button1;
Spinner spinner1;
int angle;
float x,y;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) this.findViewById(R.id.imageView1);
button1 = (Button) this.findViewById(R.id.button1);
spinner1=(Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.spinnerArray, android.R.layout.simple_spinner_item);adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter);
spinner1.setOnItemSelectedListener(new MyOnItemSelectedListener());
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
public class MyOnItemSelectedListener implements OnItemSelectedListener{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
String str=parent.getItemAtPosition(pos).toString().toUpperCase();
angle=Integer.parseInt(str);
}
public void onNothingSelected(AdapterView parent)
{
//Do Nothing
}
}
public boolean onTouch(View v, MotionEvent event) {
x = event.getX();
y = event.getY();
return true;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = Bitmap.createBitmap((Bitmap) data.getExtras().get("data"));
Bitmap mutableBitmap = photo.copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
Point point = new Point();
imageView.setImageBitmap(photo);
Canvas canvas = new Canvas(mutableBitmap);
int rectWidth = 15;
int rectHeight = 15;
point.set((int)x, (int) y);
Rect r =new Rect((point.x - rectWidth / 2), (point.y - rectHeight / 2),(point.x + rectWidth / 2),(point.y + rectHeight / 2));
canvas.save();
canvas.rotate(45);//Angle of rotation
canvas.drawRect(r,paint);
canvas.restore();
}
}
}
主要 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=".main_activity" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner1"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="37dp"
android:text="Button" />
</RelativeLayout>
字符串.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" formatted="false">StressAnalysis</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name= "spinnerPrompt">SpinnerTest</string>
<string-array name="spinnerArray">
<item> 10 </item>
<item> 15 </item>
<item> 20 </item>
<item> 25 </item>
<item> 30 </item>
<item> 35 </item>
<item> 40 </item>
<item> 45 </item>
<item> 50 </item>
<item> 55 </item>
<item> 60 </item>
<item> 65 </item>
<item> 70 </item>
<item> 75 </item>
<item> 80 </item>
<item> 85 </item>
<item> 90 </item>
</string-array>
</resources>
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stressanalysis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.stressanalysis.main_activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
控制台错误
[2013-03-13 18:09:27 - StressAnalysis] W/ResourceType( 7176): Bad XML block: header size 114 or total size 99 is larger than data size 0
[2013-03-13 18:09:27 - StressAnalysis] F:\Java Programs\StressAnalysis\res\menu\main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_settings').
[2013-03-13 19:19:32 - StressAnalysis] W/ResourceType( 7716): Bad XML block: header size 114 or total size 99 is larger than data size 0
[2013-03-13 19:19:32 - StressAnalysis] F:\Java Programs\StressAnalysis\res\menu\main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_settings').