ようこそ から取得した ListView データの追加に問題がありますSOAP
。popを作成するとListView
、次のエラーが表示されます。
04-06 00:12:47.852: W / dalvikvm (4092): threadid = 1: thread exiting with uncaught exception (group = 0x409c01f8)
04-06 00:12:48.123: E /AndroidRuntime (4092): FATAL EXCEPTION: main
04-06 00:12:48.123: E /AndroidRuntime (4092): android.content.res.Resources $NotFoundException: Resource ID # 0x7f08000c type # 0x12 is not valid
何が起こっていたのか理解できません。
問題を解決するのを手伝って、エラーで何が起こっているのかを説明してください。
package com.example.pit_testy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import com.example.pit_testy.R;
import com.example.pit_testy.soap.AsyncTaskManager;
import com.example.pit_testy.soap.GetSoapTaskTest;
import com.example.pit_testy.soap.OnAsyncTaskCompleteListener;
import com.example.pit_testy.soap.PitTestyMsg;
import com.example.library.UserFunctions;
public class TestyActivity extends Activity {
UserFunctions userFunctions;
private Button buttonWynik, buttonStartTest;
private CountDownTimer testTotalClock;
private long initialTotalTime = 300000;
private long intervalSecondTime = 1000;
private AsyncTaskManager taskMenager;
private TextView textClock, textQuestion;
private ListView listQuestions;
private ArrayAdapter<String> listAdapter;
private ArrayList<String> arrayListQuestions;
private String categoryID = "0";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testy);
taskMenager = new AsyncTaskManager(this);
textClock = (TextView)findViewById(R.id.textTimer);
textClock.setText("Czas start!");
textQuestion = (TextView)findViewById(R.id.textTrescPytania);
textQuestion.setText("Treść pytania");
testTotalClock = new CountDownTimer(initialTotalTime, intervalSecondTime) {
@Override
public void onTick(long millisUntilFinished) {
Integer milisec = new Integer(new Double(millisUntilFinished).intValue());
Integer cdSecs = milisec / 1000;
Integer minutes = (cdSecs % 3600) / 60;
Integer seconds = (cdSecs % 3600) % 60;
textClock.setText(minutes.toString()+":"+seconds.toString());
}
@Override
public void onFinish() {
textClock.setText("Koniec czasu!");
userFunctions.logoutUser(getApplicationContext());
Intent nextView = new Intent(getApplicationContext(), WynikActivity.class);
nextView.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(nextView);
}
};
loadTest(categoryID); // wybór kategorji
buttonStartTest = (Button)findViewById(R.id.buttonStart);
buttonStartTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
testTotalClock.start();
textQuestion.setText("Jak masz na imie?");
}
});
buttonWynik = (Button)findViewById(R.id.buttonWynik);
userFunctions = new UserFunctions();
buttonWynik.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
testTotalClock.cancel();
userFunctions.logoutUser(getApplicationContext());
Intent nextView = new Intent(getApplicationContext(), WynikActivity.class);
nextView.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(nextView);
}
});
testTotalClock.cancel();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.testy, menu);
return true;
}
private void loadTest(String category) {
Map<String, String> map = new HashMap<String, String>();
map.put("aid", "1");
map.put("categories", category);
GetSoapTaskTest task = new GetSoapTaskTest();
taskMenager.executeTask(task, GetSoapTaskTest.createRequest("getCategories", new JSONObject(map).toString()), "Wykonano executeTask",
new OnAsyncTaskCompleteListener<PitTestyMsg>() {
ArrayList<String> arrayListQuestions = new ArrayList<String>();
@Override
public void onTaskCompleteSuccess(PitTestyMsg result) {
if (result.errorCode == 0){
for (Map <String, String> var : result.data) {
Log.i("SoapCategories", "Testy pobrane = " + var.get("name"));
arrayListQuestions.add(var.get("name"));
}
taskMenager.onPostExecute(arrayListQuestions);
Intent mainTest = new Intent(getApplicationContext(), TestyActivity.class);
startActivity(mainTest);
}else{
Log.i("SoapCategories", "Testy niepobrane");
}
}
@Override
public void onTaskFailed(Exception cause) {
Log.e("Soap", cause.getMessage(), cause);
}
});
}
}
public final class AsyncTaskManager implements IProgressTracker {
private final ProgressDialog progressDialog;
private ListView listQuestions;
private ArrayAdapter<String> listAdapter;
private Context myContext;
public AsyncTaskManager(Context context) {
myContext = context;
this.progressDialog = new ProgressDialog(context);
this.progressDialog.setCancelable(false);
this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
}
/**
* Executes a task in the background thread, while displaying a busy dialog (non cancellable).
*
* @param task
* {@link AbstractProgressableAsyncTask}
* @param request
* request for the background task
* @param progressLabel
* label to be displayed when the progress dialog is being displayed.
* @param onTaskCompletedListener
* {@link OnAsyncTaskCompleteListener} to be notified once the task is completed.
*/
public <T, P> void executeTask(AbstractProgressableAsyncTask<P, T> task, P request, CharSequence progressLabel,
OnAsyncTaskCompleteListener<T> onTaskCompletedListener) {
this.progressDialog.setMessage(progressLabel);
task.setOnTaskCompletionListener(onTaskCompletedListener);
//task.setProgressTracker(this);
task.execute(request);
}
// ------------------------------------------------------------------------
// Progress Handlers
// ------------------------------------------------------------------------
@Override
public void onStartProgress() {
progressDialog.show();
}
@Override
public void onStopProgress() {
progressDialog.dismiss();
}
@Override
public void onPostExecute(ArrayList<String> list){
listAdapter = new ArrayAdapter<String>(myContext, R.id.listaPytan, list);
listQuestions = (ListView)((Activity) myContext).findViewById(R.id.listaPytan);
listQuestions.setAdapter(listAdapter);
Log.i("ListView", "Lista wyswietlona");
}
}