在android程序编码中请求帮助 [英] Request assistance in an android program coding
问题描述
我在使用Android Studio创建程序时遇到了问题。但是我遇到了一些编码错误。任何帮助将不胜感激。
我尝试过:
这些是我遇到的一些错误
I'm having issues in creating a program using Android Studio.But i get a little coding errors. Any assistance would be appreciated.
What I have tried:
These are a few errors i'm having
public void getEditTextGPA() {
String str = ((EditText) findViewById(R.id.GPAEditText)).getText().toString();
if (str.trim().equalsIgnoreCase(".")) {
showAlertMessage("Error", ". is not a valid number");
this.errorMessageDisplayed = true;
}
while (true) {
if (this.userInputGPA > 4.00D) {
showAlertMessage("ERROR: CGPA Input", "You cannot have CGPA of over 4.00.");
this.errorMessageDisplayed = true;
}
return;
if (str.trim().matches("")) {
this.userInputGPA = -1.0F;
continue;
}
this.userInputGPA = Float.parseFloat(str);
}
在`this.userInputGPA = -1.0F;`为无法访问的声明时出错
Error at `this.userInputGPA=-1.0F;` as unreachable statement
public void getGPAValueForGrade(String paramString, int paramInt) {
String[] arrayOfString = {"A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "E", "Grade"};
int i = 0;
if (i >= 12)
return;
String str = arrayOfString[i];
if (paramString.trim().equalsIgnoreCase(str))
switch (i) {
default:
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
}
while (true) {
i++;
break;
this.GPAValueArray[paramInt] = 4.0F;
continue;
this.GPAValueArray[paramInt] = 3.67F;
continue;
this.GPAValueArray[paramInt] = 3.33F;
continue;
this.GPAValueArray[paramInt] = 3.0F;
continue;
this.GPAValueArray[paramInt] = 2.67F;
continue;
this.GPAValueArray[paramInt] = 2.33F;
continue;
this.GPAValueArray[paramInt] = 2.0F;
continue;
this.GPAValueArray[paramInt] = 1.67F;
continue;
this.GPAValueArray[paramInt] = 1.33F;
continue;
this.GPAValueArray[paramInt] = 1.0F;
continue;
this.GPAValueArray[paramInt] = 0.0F;
continue;
}
}
错误在第1个`继续;`作为无法访问的声明
Error at the 1st `continue;` as unreachable statement
public void getTotalGPAValueFromSpinnerFloat() {
getGPAValueForGrade(this.gpaSpinnerOne.getSelectedItem().toString(), 0);
int i = 0 + 1;
getGPAValueForGrade(this.gpaSpinnerTwo.getSelectedItem().toString(), i);
int j = i + 1;
getGPAValueForGrade(this.gpaSpinnerThree.getSelectedItem().toString(), j);
int k = j + 1;
getGPAValueForGrade(this.gpaSpinnerFour.getSelectedItem().toString(), k);
int m = k + 1;
getGPAValueForGrade(this.gpaSpinnerFive.getSelectedItem().toString(), m);
int n = m + 1;
getGPAValueForGrade(this.gpaSpinnerSix.getSelectedItem().toString(), n);
int i1 = n + 1;
getGPAValueForGrade(this.gpaSpinnerSeven.getSelectedItem().toString(),i1);
int i2 = i1 + 1;
getGPAValueForGrade(this.gpaSpinnerEight.getSelectedItem().toString(), i2);
(i2 + 1);
}
最后一部分(i2 + 1)错误而不是声明
Error at the last part (i2 + 1) as not a statement
public void setTextResults() {
TextView localTextView1 = (TextView) findViewById(R.id.GPATextView);
TextView localTextView2 = (TextView) findViewById(R.id.CGPATextView);
float f1 = 0.0F;
float f2 = 0.0F;
int i = 0;
float f3;
if (i >= 8) {
f3 = f1 / f2;
if (f2 != 0.0F)
break label153;
localTextView1.setText("GPA: 0.0");
}
float f4;
float f5;
while (true) {
if (this.userInputGPA == -1.0F)
break label258;
f4 = f1 + this.userInputGPA * this.userInputUnits;
f5 = f2 + this.userInputUnits;
if (f5 != 0.0F)
break label203;
localTextView2.setText("CGPA: 0.0");
return;
if (this.GPAValueArray[i] != -1.0F) {
f1 += this.GPAValueArray[i] * this.UnitValueArray[i];
f2 += this.UnitValueArray[i];
}
在'break label153`,`break label258`& `break label203`为不可定义的标签
Errors at `break label153`,`break label258` & `break label203` as undefinable label
i++;
break;
label153:
StringBuilder localStringBuilder1 = new StringBuilder("GPA: ");
Object[] arrayOfObject1 = new Object[1];
arrayOfObject1[0] = Float.valueOf(f3);
localTextView1.setText(String.format("%.2f", arrayOfObject1));
StringBuilder中的错误localStringBuilder1 = new StringBuilder(GPA:)`作为非声明
Error in `StringBuilder localStringBuilder1 = new StringBuilder("GPA: ")` as not a statement
label203:
Float f6 = f4 / f5;
StringBuilder localStringBuilder3 = new StringBuilder("CGPA: ");
Object[] arrayOfObject3 = new Object[1];
arrayOfObject3[0] = Float.valueOf(f6);
localTextView2.setText(String.format("%.2f", arrayOfObject3));
return;
`Float f6 = f4出错/ f5`不是语句
Error in `Float f6 = f4 / f5` as not a statement
推荐答案
在第一种情况下,你有一个返回
语句你的方法所以永远无法达到错误信息中的陈述。
在第二种情况下你有一个开关
阻止什么都不做。然后你有一个break
语句和一些continue
语句,这些语句阻止任何有用的事情。
在第三种情况下,你有一个非statemnt(i2 + 1);
等
我建议回到 Java™教程 [ ^ ]并花一些时间学习Java。
In the first case you have areturn
statement in the middle of your method so the statement in the error message can never be reached.
In the second case you have aswitch
block that does nothing. You then have abreak
statement and a number ofcontinue
statements that prevent anything useful being done.
In the third case you have a non-statemnt(i2 + 1);
etc.
I would suggest going back to The Java™ Tutorials[^] and spending some time learning Java.
这篇关于在android程序编码中请求帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!