私はアンドロイドアプリケーションを開発しています。受験アプリです。ユーザーが回答をクリックすると、アプリケーション$setContentView();
は同じアクティビティでレイアウトを変更します。ただし、レイアウトのエラーが発生します原因: java.lang.NumberFormatException: '@2131230721' を整数として解析できません
私のレイアウト ファイルは以下のとおりです。必要に応じて、私のプロジェクトを myserver に配置できます。アクティビティ コードを貼り付けることができますが、これは基本的なものにsetContentView()
すぎません。ID の 1 つがエラーの原因になっていると思いますが、見つかりませんでした。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:id="@+id/soruNoIleriVeGeri"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.01"
android:weightSum="1" >
<LinearLayout
android:id="@+id/SoruLayout"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@drawable/question_top_plain"
android:weightSum="1" >
<LinearLayout
android:id="@+id/OncekiSoru"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/qIPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/back_button"
android:onClick="qIPrevious"
android:paddingLeft="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="57dp"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/about_question" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<ImageButton
android:id="@+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add_favourite" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/goToQuestion"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:onClick="onshowQuestion"
android:src="@drawable/show_question" />
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="45dp"
android:layout_weight="0.57" >
<ImageButton
android:id="@+id/homeButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/tab_home"
android:onClick="goHome" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/next_button"
android:onClick="qINextQuestion" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/question_top_plain"
android:weightSum="1" >
<LinearLayout
android:id="@+id/resultIconPlain"
android:layout_width="84dp"
android:layout_height="fill_parent"
android:paddingLeft="20dp" >
</LinearLayout>
<LinearLayout
android:layout_width="234dp"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/resultView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.13"
android:gravity="center_horizontal"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#111" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="59dp"
android:background="@drawable/question_top_plain" >
<LinearLayout
android:id="@+id/dogruCevap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.01"
android:weightSum="1" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/StatikDogruCevap"
android:layout_width="126dp"
android:layout_height="wrap_content"
android:text="@string/StatikDogruCevap"
android:textStyle="@style/boldText" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.01" >
<TextView
android:id="@+id/dogruCevapView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingRight="10dp"
android:text="TextView"
android:textStyle="@style/rightAnswer" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/cevabiniz"
android:layout_width="fill_parent"
android:layout_height="54dp"
android:layout_weight="0.01"
android:weightSum="1" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/cevabinizView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingLeft="10dp"
android:text="TextView"
android:textStyle="@style/rightAnswer" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/StatikCevap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/StatikCevap"
android:textStyle="@style/boldText" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="350px"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/dogruCevapAyrinti"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.60"
android:isScrollContainer="true"
android:minHeight="400px"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbars="vertical" >
<TextView
android:id="@+id/dogruCevapAyrintiView"
android:layout_width="fill_parent"
android:layout_height="324dp"
android:scrollHorizontally="false"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbars="vertical"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#111" >
</TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
エラーコードとmyActivityはトルコ語の変数名で申し訳ありません
at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
at
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
java.lang.reflect.InvocationTargetException
at android.widget.TextView.<init>(TextView.java:320)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 41 more
java.lang.NumberFormatException: unable to parse '@2131230721' as integer
at java.lang.Integer.parse(Integer.java:374)
at java.lang.Integer.parseInt(Integer.java:363)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:121)
at android.content.res.TypedArray.getInt(TypedArray.java:201)
at android.widget.TextView.<init>(TextView.java:647)
package com.eandroid.workingSet;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.eandroid.entity.Question;
public class QuestionInterfaceActivity extends Activity {
LinearLayout layoutForA;
LinearLayout layoutForB;
LinearLayout layoutForC;
LinearLayout layoutForD;
LinearLayout layoutForE;
LinearLayout choiceATotalPlain;
LinearLayout choiceBTotalPlain;
LinearLayout choiceCTotalPlain;
LinearLayout choiceDTotalPlain;
LinearLayout choiceETotalPlain;
LinearLayout allTotalPlain;
List<Question> questionList = new ArrayList<Question>();
Node node = null;
NodeList nodeList = null;
NodeList nodeListForTestInfo = null;
InputStream is = null;
private TextView choiceA;
private TextView choiceB;
private TextView choiceC;
private TextView choiceD;
private TextView choiceE;
private TextView questionText;
private TextView soruIdText;
private TextView soruIdEv;
private TextView soruBilgileriView;
private TextView cevabinizView;
private TextView dogruCevapView;
private TextView dogruCevapAyrintiView;
private TextView resultView;
private int currentQuestionIndex;
Question currentQuestion = null;
private String testName = null;
HttpClient httpclient;
HttpPost httppost;
ArrayList<NameValuePair> postParameters;
HttpResponse response;
InputStream contentStream;
private String rightAnswers = "";
private String userAnswers = "";
private String resultOfAnswers = "";
private String userId = "1";
private static String testRelationId;
private LinearLayout resultIconPlain;
private static String willPostUrl =
"http://balabanhafriyat.com/SchoolProjectWebSide/postFromPhone/SendDataFromPhone";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
Toast.makeText(QuestionInterfaceActivity.this, "Hoşgeldin Hacı",
Toast.LENGTH_SHORT).show();
}
settleOrientation();
Bundle extras = getIntent().getExtras();
if (extras != null) {
testName = extras.getString("testName");
}
try {
is = getAssets().open(testName);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(is));
doc.getDocumentElement().normalize();
nodeList = doc.getElementsByTagName("question");
nodeListForTestInfo = doc.getElementsByTagName("testInfo");
Node testNode = nodeListForTestInfo.item(0);
testRelationId = parseItToStringByName(testNode, "testRelationId");
} catch (Exception e) {
e.printStackTrace();
}
currentQuestionIndex = 1;
showQuestion();
}
public void settleOrientation() {
int setLayout = getResources().getConfiguration().orientation;
switch (setLayout) {
case 1:
setContentView(R.layout.buttontry);
loadDesign();
break;
case 2:
setContentView(R.layout.buttontry);
break;
default:
break;
}
}
public void callEvaluationActivity(int optionToSeeQuestion,
String userAnswer) {
setContentView(R.layout.evaluation_screen);
// resultView = (TextView) findViewById(R.id.resultView);
cevabinizView = (TextView) findViewById(R.id.cevabiniz);
dogruCevapView = (TextView) findViewById(R.id.rightAnswer);
dogruCevapAyrintiView = (TextView)
findViewById(R.id.dogruCevapAyrintiView);
// soruBilgileriView.setText(currentQuestion.getShortInfo());
dogruCevapAyrintiView.setText(currentQuestion.getRightAnswerDetail());
dogruCevapView.setText(currentQuestion.getRightAnswer());
if (optionToSeeQuestion == 2) {
cevabinizView.setText(userAnswer);
if (currentQuestion.getRightAnswer().equals(userAnswer)) {
resultView.setTextColor(Color.GREEN);
resultView.setText("Doğru Cevap");
resultOfAnswers = resultOfAnswers + "1$";
} else {
resultView.setTextColor(Color.RED);
resultView.setText("Cevap Yanlış !!! ");
resultOfAnswers = resultOfAnswers + "0$";
}
userAnswers = userAnswers + userAnswer + "$";
rightAnswers = rightAnswers + currentQuestion.getRightAnswer()
+ "$";
}
}
public void loadDesign() {
allTotalPlain = (LinearLayout) findViewById(R.id.allTotalPlain);
allTotalPlain.setBackgroundResource(R.drawable.yellow_button);
choiceATotalPlain = (LinearLayout) findViewById(R.id.choiceTotalPlain);
choiceBTotalPlain = (LinearLayout) findViewById(R.id.choiceBTotalPlain);
choiceCTotalPlain = (LinearLayout) findViewById(R.id.choiceCTotalPlain);
choiceDTotalPlain = (LinearLayout) findViewById(R.id.choiceDTotalPlain);
choiceETotalPlain = (LinearLayout) findViewById(R.id.choiceETotalPlain);
layoutForA = (LinearLayout) findViewById(R.id.abuttonLayout);
layoutForB = (LinearLayout) findViewById(R.id.bButtonLayout);
layoutForC = (LinearLayout) findViewById(R.id.cButtonLayout);
layoutForD = (LinearLayout) findViewById(R.id.dButtonLayout);
layoutForE = (LinearLayout) findViewById(R.id.ebuttonLayout);
createButton("A");
createButton("B");
createButton("C");
createButton("D");
createButton("E");
}
private void showQuestion() {
questionText = (TextView) findViewById(R.id.soruTextView);
choiceA = (TextView) findViewById(R.id.choiceA);
choiceB = (TextView) findViewById(R.id.choiceB);
choiceC = (TextView) findViewById(R.id.choiceC);
choiceD = (TextView) findViewById(R.id.choiceD);
choiceE = (TextView) findViewById(R.id.choiceE);
currentQuestion = setQuestionFieldById(currentQuestionIndex);
questionText.setText(currentQuestion.getQuestionText());
choiceA.setText(currentQuestion.getChoiceA());
choiceB.setText(currentQuestion.getChoiceB());
choiceC.setText(currentQuestion.getChoiceC());
choiceD.setText(currentQuestion.getChoiceD());
choiceE.setText(currentQuestion.getChoiceE());
/*
* consumerAnswer .setOnCheckedChangeListener(new
* OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup
* group, int checkedId) { if (choiceA.getId() == checkedId) {
* approveAnswer(2, "A"); } if (choiceB.getId() == checkedId) {
*
* approveAnswer(2, "B"); } if (choiceC.getId() == checkedId) {
*
* approveAnswer(2, "C"); } if (choiceD.getId() == checkedId) {
*
* approveAnswer(2, "D"); } if (choiceE.getId() == checkedId) {
*
* approveAnswer(2, "E"); } } });
*/
}
private void approveAnswer(int optionToSeeQuestion, final String userChoice) {
callEvaluationActivity(optionToSeeQuestion, userChoice);
}
// Eger optionToSeeQuestion 1 ise kullanıcının cevap karsılastırılması
// yapılmamalı 2 ise yapılmalı
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == 999) {
if (data.hasExtra("action")) {
String aim = data.getExtras().getString("aim");
Toast.makeText(this, "Ne yapmak istiyorsunuz" + aim,
Toast.LENGTH_LONG).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
public void qINextQuestion(View view) {
if (currentQuestionIndex == nodeList.getLength() - 1) {
Toast.makeText(QuestionInterfaceActivity.this, "Son Sorudasınız",
Toast.LENGTH_SHORT).show();
} else {
currentQuestionIndex++;
settleOrientation();
showQuestion();
}
}
public void qIPrevious(View view) {
if (currentQuestionIndex == 1) {
Toast.makeText(QuestionInterfaceActivity.this, "İlk Sorudasınız",
Toast.LENGTH_SHORT).show();
} else {
currentQuestionIndex--;
settleOrientation();
showQuestion();
}
}
public Question setQuestionFieldById(int questionId) {
Question q = new Question();
for (int i = 0; i < nodeList.getLength(); i++) {
node = nodeList.item(i);
int idFromXml = Integer.parseInt(parseItToStringByName(node,
"questionNumber"));
if (questionId == idFromXml) {
q.setQuestionId(questionId);
q.setChoiceA(parseItToStringByName(node, "choiceA"));
q.setChoiceB(parseItToStringByName(node, "choiceB"));
q.setChoiceC(parseItToStringByName(node, "choiceC"));
q.setChoiceD(parseItToStringByName(node, "choiceD"));
q.setChoiceE(parseItToStringByName(node, "choiceE"));
q.setQuestionText(parseItToStringByName(node,
"questionText"));
q.setRightAnswer(parseItToStringByName(node,
"rightAnswer"));
q.setRightAnswerDetail(parseItToStringByName(node,
"answerDetail"));
}
}
return q;
}
public String parseItToStringByName(Node node, String nodeName) {
Element mainELement = (Element) node;
NodeList questionList = mainELement.getElementsByTagName(nodeName);
Element questionElement = (Element) questionList.item(0);
NodeList question = questionElement.getChildNodes();
String result = question.item(0).getNodeValue().replaceAll("\n", "")
.replaceAll("\t", "");
result.trim();
return result;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.landscapequestion);
showQuestion();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.buttontry);
showQuestion();
}
}
@Override
public void onBackPressed() {
beforeQuitProcess();
super.onBackPressed();
}
public void beforeQuitProcess() {
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("testId", testRelationId));
postParameters
.add(new BasicNameValuePair("rightAnswers", rightAnswers));
postParameters.add(new BasicNameValuePair("userAnswers", userAnswers));
postParameters.add(new BasicNameValuePair("userAnswerAndResult",
resultOfAnswers));
postParameters.add(new BasicNameValuePair("userId", userId));
PostDataToServer postDataToServer = new PostDataToServer();
HttpResponse response = postDataToServer.postData(willPostUrl,
postParameters);
contentStream = postDataToServer.parseHttpResponseToStream(response);
String responseFromServer = postDataToServer
.convertStreamToString(contentStream);
if (responseFromServer != null) {
Toast.makeText(QuestionInterfaceActivity.this, "Kayıt Edildi",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
Toast.makeText(QuestionInterfaceActivity.this, "Çıktı Hacı",
Toast.LENGTH_SHORT).show();
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
savedInstanceState.putBoolean("MyBoolean", true);
savedInstanceState.putDouble("myDouble", 1.9);
savedInstanceState.putInt("MyInt", 1);
savedInstanceState.putString("MyString", "Welcome back to Android");
// etc.
super.onSaveInstanceState(savedInstanceState);
finish();
}
public void onDestroy() {
super.onDestroy();
android.os.Process.killProcess(android.os.Process.myPid());
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
Toast.makeText(QuestionInterfaceActivity.this, "Hoşgeldin Hacı",
Toast.LENGTH_SHORT).show();
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");
double myDouble = savedInstanceState.getDouble("myDouble");
int myInt = savedInstanceState.getInt("MyInt");
String myString = savedInstanceState.getString("MyString");
}
@Override
protected void onResume() {
super.onResume();
}
public void onshowAnswer(View v) {
callEvaluationActivity(1, "A");
}
public void onshowQuestion(View view) {
setContentView(R.layout.buttontry);
loadDesign();
showQuestion();
}
public void goHome(View view) {
beforeQuitProcess();
Intent intent = new Intent(QuestionInterfaceActivity.this,
LoginEvaluation.class);
intent.putExtra("userId", userId);
startActivity(intent);
}
public void createButton(final String text) {
Button button = new Button(this);
button.setTextColor(Color.parseColor("#000000"));
button.setBackgroundResource(R.drawable.button_selector);
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
clickMeMyFriend(view, text);
}
});
button.setText(text);
if (text.equals("A")) {
layoutForA.addView(button);
}
if (text.equals("B")) {
layoutForB.addView(button);
}
if (text.equals("C")) {
layoutForC.addView(button);
}
if (text.equals("D")) {
layoutForD.addView(button);
}
if (text.equals("E")) {
layoutForE.addView(button);
}
}
private void clickMeMyFriend(View view, String chooice) {
if (chooice.equals("A")) {
approveAnswer(2, "A");
}
if (chooice.equals("B")) {
approveAnswer(2, "B");
}
if (chooice.equals("C")) {
approveAnswer(2, "C");
}
if (chooice.equals("D")) {
approveAnswer(2, "D");
}
if (chooice.equals("E")) {
approveAnswer(2, "E");
}
}
public void onTotalAClick(View view) {
switch (view.getId()) {
case R.id.choiceTotalPlain:
choiceATotalPlain.setBackgroundResource(R.drawable.black_button);
approveAnswer(2, "A");
break;
case R.id.choiceBTotalPlain:
choiceBTotalPlain.setBackgroundResource(R.drawable.black_button);
approveAnswer(2, "B");
break;
case R.id.choiceCTotalPlain:
approveAnswer(2, "C");
choiceCTotalPlain.setBackgroundResource(R.drawable.black_button);
break;
case R.id.choiceDTotalPlain:
approveAnswer(2, "D");
choiceDTotalPlain.setBackgroundResource(R.drawable.black_button);
break;
case R.id.choiceETotalPlain:
approveAnswer(2, "E");
choiceETotalPlain.setBackgroundResource(R.drawable.black_button);
break;
default:
break;
}
}
}
助けてくれてありがとう