آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

مشکل در طراحی و برنامه نویسی پروژه Calculator (سری آموزش های جدید)

Sina  8 سال پیش  8 سال پیش
0 0

با عرض سلام و خسته نباشید خدمت استاد گرامی و دوستان عزیز:

من طراحی لایه رو مو به مو طبق گفته های استاد طراحی کردم البته در محیط اندروید استودیو جدید ، اما چه در activity_main.xml و چه در MainActivity.java کلی پیغام خطا داده.لطفا راهنمایی کنید ممنون میشم.

 برای این سوال 7 پاسخ وجود دارد. مشاهده پاسخ صحیح
پاسخ به سوال 
Mahdidrv  8 سال پیش
0 0

سلام دوست عزیز

بهتر بود بر روی فایل R که خطا میداد نگه میداشتین و از ارورش عکس میذاشتین که خطا مربوطه قابل تشخیص باشه ;)

معمولا خطای فایل R برای شناخته نشدن اون هست، از منوی Build ابتدا Clean project و بعد Rebuild کنین احتمالا باید درست بشه...

اگه جواب نداد میتونین کدهای برنامه رو کپی کنین و پروژه جدیدی ایجاد کنین.

0 0
سلام و خسته نباشید من اینکاری که گفتید (هم Rebuild و هم اینکه از اول یه پروژه دیگه نوشتم ) رو کردم اما همین پیغام ها دوباره ظاهر میشن روی R هم نگه دارم این رو نشون میده : Cannot resolve symbol 'R (8 سال پیش)
پاسخ به سوال 
FSR  8 سال پیش
0 0

سلام

هر چی Import R داخل پروژه داری (داخل کلاس ها در قسمت بالا) حذف کن بعدش کامپایل رو بزن ایکونی شبیه به چکش سبز رنگ بالا هستش

مشکل Import R معمولا موقعی پیش میاد که مثلا عکس یا فایلی داخل res داشته باشی که با حروف بزرگ نوشته شده باشه و از این جور مشکلات 

0 0
این کار رو هم کردم دوباره اینجوری شد (8 سال پیش)
0 0
به احتمال زیاد مشکل از activity_main هستش بررسی کنید ببنید مشکل از کجاست (8 سال پیش)
0 0
به نظرم مربوط به موضوع تغییر لایه از Constraint Layout به Relative Layout اینا باشه؟؟ (8 سال پیش)
0 0
تغییرش بدید ببنید درست میشه یا نه ولی هرچی هست مربوط میشه به xml (8 سال پیش)
پاسخ به سوال 
Sina  8 سال پیش
0 0

هرچی نگاه میکنم نمیدونم باید چیکارش کنم چون مو به مو گفته های استاد رو انجام دادم فقط با این تفاوت که من در اندروید استودیو جدید این پروژه رو نوشتم که مجبور شدم اول کار Constraint Layout رو حذف کنم و به جاش Relative Layout نوشتم.اینم عکس از تمام xml و خطاهایی که داده

0 0
منم نگاه کردم مشکلی ندیدم به جای این xml یه xml دیگه ای ست کنید ببنید مشکل از xml هستش یا از برنامه (8 سال پیش)
0 0
اصلا درست نمیشه که نمیشه ... عجیبه!!! (8 سال پیش)
0 0
این خطاها هیچ کدومشون موقع برنامه نویسی نیستند.وقتی که من دستورات رو مینویسم هیچ خطایی نمیگیره و همشون درست وارد میشن . اما موقع اتمام کار وقتی که دکمه ی Play رو میزنم اونموقعه که این خطاهاه میاد و میگه Cannot resolve symbol 'R (8 سال پیش)
0 0
سلام اگه میشه به جای عکس گذاشتن از xml، خود متن سورس کد هاتون رو اینجا کپی کنید تا بتونیم داخل محیط اندروید استودیو بررسیشون کنیم (8 سال پیش)
پاسخ به سوال 
Sina  8 سال پیش
0 0

سلام اینم از متن ایکس ام ال دوست عزیز

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="sina.afkhamzadeh.calculator.MainActivity">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical">

<TextView
android:id="@+id/txt_history"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|right"
android:textColor="#555555"
android:textSize="18dp"/>

<TextView
android:id="@+id/txt_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|right"
android:text="0"
android:textColor="#000000"
android:textSize="30dp"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">

<Button
android:id="@+id/btn_clearEntity"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="CE"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="C"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="<"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_division"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="/"
android:textColor="#000000"
android:textSize="22dp"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">

<Button
android:id="@+id/btn_7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="7"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_8"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="8"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_9"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="9"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_multiply"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="X"
android:textColor="#000000"
android:textSize="22dp"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">

<Button
android:id="@+id/btn_4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="4"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="5"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="6"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_minus"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="-"
android:textColor="#000000"
android:textSize="22dp"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">

<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="1"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="2"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="3"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_plus"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="+"
android:textColor="#000000"
android:textSize="22dp"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">

<Button
android:id="@+id/btn_sign"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="+-"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="0"
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_dot"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="."
android:textColor="#000000"
android:textSize="22dp"/>

<Button
android:id="@+id/btn_equal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:width="0dp"
android:text="="
android:textColor="#000000"
android:textSize="22dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
پاسخ به سوال 
Sina  8 سال پیش
0 0

اینم از متن MainActivity.java :

package sina.afkhamzadeh.calculator;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

Button btn_0;
Button btn_1;
Button btn_2;
Button btn_3;
Button btn_4;
Button btn_5;
Button btn_6;
Button btn_7;
Button btn_8;
Button btn_9;
Button btn_dot;
Button btn_sign;
Button btn_back;
Button btn_clear;
Button btn_clearEntity;
Button btn_division;
Button btn_multiply;
Button btn_minus;
Button btn_plus;
Button btn_equal;

TextView txt_history;
TextView txt_result;

boolean mustReset = false;
float currentResult = 0;
String operand = "";

public void toggleSign(){
String resultValue = txt_result.getText().toString();
if (resultValue.contains("-")){
resultValue = resultValue.replace("-" , "");
}else{
resultValue = "-" + resultValue;
}
txt_result.setText(resultValue);
}

public void compute(String nextOperand) {
String resultValue = txt_result.getText().toString();
float resultNumber = Float.parseFloat(resultValue);
if (operand.equals("+")) {
currentResult += resultNumber;
} else if (operand.equals("-")) {
currentResult -= resultNumber;
} else if (operand.equals("*")) {
currentResult *= resultNumber;
} else if (operand.equals("/")) {
currentResult /= resultNumber;
} else if (operand.equals("")) {
currentResult = resultNumber;
}

String oldHistory = txt_history.getTag().toString();
txt_history.setText(oldHistory + " " + resultNumber + " " + nextOperand);
txt_result.setText("" + currentResult);
operand = nextOperand;
mustReset = true;
}
public void processEqual() {
compute("");
txt_history.setText("");
}

public void doOperand(String nextOperand) {
compute(nextOperand);
}

public void backOneLetter() {
String value = txt_result.getText().toString();
String newValue = value.substring(0, value.length() - 1);
txt_result.setText(newValue);
}

public void addPoint() {
if (mustReset) {
txt_result.setText("0");
mustReset = false;
}
String oldValue = txt_result.getText().toString();
if (oldValue.contains(".")) {
return;
}
if (oldValue.length() > 9) {
return;
}
txt_result.setText(oldValue + ".");
}

public void appendNumber(int num) {
if (mustReset) {
txt_result.setText("");
mustReset = false;
}
String oldValue = txt_result.getText().toString();
if (oldValue.length() > 9) {
return;
}
if (oldValue.equals("0")) {
if (num == 0) {
return;
} else {
oldValue = "";
}
}
txt_result.setText(oldValue + num);
}


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn_0 = (Button)findViewById(R.id.btn_0);
btn_1 = (Button)findViewById(R.id.btn_1);
btn_2 = (Button)findViewById(R.id.btn_2);
btn_3 = (Button)findViewById(R.id.btn_3);
btn_4 = (Button)findViewById(R.id.btn_4);
btn_5 = (Button)findViewById(R.id.btn_5);
btn_6 = (Button)findViewById(R.id.btn_6);
btn_7 = (Button)findViewById(R.id.btn_7);
btn_8 = (Button)findViewById(R.id.btn_8);
btn_9 = (Button)findViewById(R.id.btn_9);
btn_dot = (Button)findViewById(R.id.btn_dot);
btn_sign = (Button)findViewById(R.id.btn_sign);
btn_back = (Button)findViewById(R.id.btn_back);
btn_clear = (Button)findViewById(R.id.btn_clear);
btn_clearEntity = (Button)findViewById(R.id.btn_clearEntity);
btn_division = (Button)findViewById(R.id.btn_division);
btn_multiply = (Button)findViewById(R.id.btn_multiply);
btn_minus = (Button)findViewById(R.id.btn_minus);
btn_plus = (Button)findViewById(R.id.btn_plus);
btn_equal = (Button)findViewById(R.id.btn_equal);

txt_history = (TextView)findViewById(R.id.txt_history);
txt_result = (TextView)findViewById(R.id.txt_result);

btn_clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txt_result.setText("0");
txt_history.setText("");
currentResult = 0;
mustReset = false;
}
});

btn_clearEntity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txt_result.setText("0");
}
});

View.OnClickListener numberListener = new View.OnClickListener(){
@Override
public void onClick(View view){
int index = Integer.parseInt(view.getTag().toString());
appendNumber(index);
}
};
btn_0.setOnClickListener(numberListener);
btn_1.setOnClickListener(numberListener);
btn_2.setOnClickListener(numberListener);
btn_3.setOnClickListener(numberListener);
btn_4.setOnClickListener(numberListener);
btn_5.setOnClickListener(numberListener);
btn_6.setOnClickListener(numberListener);
btn_7.setOnClickListener(numberListener);
btn_8.setOnClickListener(numberListener);
btn_9.setOnClickListener(numberListener);

View.OnClickListener operandListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
doOperand(view.getTag().toString());
}
};
btn_division.setOnClickListener(operandListener);
btn_multiply.setOnClickListener(operandListener);
btn_minus.setOnClickListener(operandListener);
btn_plus.setOnClickListener(operandListener);

btn_equal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
processEqual();
}
});

btn_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
backOneLetter();
}
});

btn_dot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addPoint();
}
});

btn_sign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleSign();
}
});

}
}
پاسخ به سوال 
Abbas64  8 سال پیش
+2 0

 پاسخ صحیح


پیدا کردن مشکلش که خیلی راحت بود زمانی که زدم اجرا خود اندروید استودیو منو به خطی از کد شما که اشکال داشت هدایت کرد و من با اصلاح اون خط تونستم مشکل رو حل کنم. حالا شاید دلیل اینکه خود اندروید استودیو منو هدایت کرد به خط ارور از فایل xml، این باشه که من از نسخه 3 اندروید استودیو استفاده می کنم و پیشنهاد میکنم شما هم آپدیت کنید.

و اما مشکل از این خطه: 


android:text="<"

که کاراکتر < به عنوان متن تنظیم شده
+1 0
سلام.منم دقیقا همین مشکل دوستمونو دارم.خب مگه مشکلش چیه که از کاراکتر > استفاده بشه ؟اگه ایرادی باشه که باید واسه ی آقای آقاجانی هم مشکل درست شه ولی واسه ایشون درست کار میکنه؟ (8 سال پیش)
+1 0
احتمالا مشکل که بخاطر اینه که از ConstraintLayout استفاده میکنم ولی آقای آقاجانی از RelativeLayout استفاده میکنن (8 سال پیش)
+1 0
نمیدونم چرا ولی هر کاراکتری بجای < < > اینا بزارم درست کار میکنه.لطفا اگه دلیلشو متوجه دین به ما هم بگین.مرسی بابت کمکتون abbas64 (8 سال پیش)
+1 0
سلام آقا عباس دستتون درد نکنه واقعا خیلی ممنون . خدا خیرتون بده . (8 سال پیش)
پاسخ به سوال 
Abbas64  8 سال پیش
+5 0

با سلام

برخی کاراکتر برای xml غیر مجاز به حساب می آیند که نمیتوان برای تنظیم متن یک ویو یا هر مورد دیگری به طور مستقیم از آن ها استفاده کرد بلکه باید از جایگزین آنها استفاده کرد. در جدول زیر لیست کاراکترهای غیر مجاز و جایگزین ها ی آنها را میبینید:

طبق این تصویر شما باید بنویسید: 

android:text="&gt;"

0 0
زنده باشی کارم حل شد خیلی ممنون از راهنماییتون آقا عباس گل (8 سال پیش)

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .