Monday, November 25, 2013

Error #1009: Cannot access a property or method of a null object reference. -AS3 [android help]


Error #1009: Cannot access a property or method of a null object reference. -AS3



i got this error:



TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TriviaGameDeluxe/saveScore()[TriviaGameDeluxe::frame102:19]


This is my code:



//**//
playAgainbutton.addEventListener(MouseEvent.CLICK,saveScore);


function saveScore(event:MouseEvent) { // Save the score


if (savedSN == null) { // Check if a game save is created. If it is not, create one
trace("New game save created");
savedSN = { // Set the varible 'savedSN'
name1:"-",
name2:"-",
name3:"-",
name4:"-",

score1:"-",
score2:"-",
score3:"-",
score4:"-"};
soSavedScNa.data.nameScore = savedSN; // Set the data in the save file to the
savedSN variable
soSavedScNa.flush(); // Overwrite existing save file

}

//**// Save the score
if ((gameScore > savedSN.score1 || savedSN.score1 == "-") &&
gameScore != 0) {
trace("Score 1");
savedSN = { // Set the date the savedSN varible will have
name1:PName.text,
name2:savedSN.name1,
name3:savedSN.name2,
name4:savedSN.name3,
score1:gameScore,
score2:savedSN.score1,
score3:savedSN.score2,
score4:savedSN.score3};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);
cleanUp();
gotoAndStop(1); // Go to the start menu
} else if ((gameScore > savedSN.score2 || savedSN.score2 == "-") &&
gameScore != 0) {
trace("Score 2");
savedSN = { // Set the date the savedSN varible will have
name1:savedSN.name1,
name2:PName.text,
name3:savedSN.name2,
name4:savedSN.name3,
score1:savedSN.score1,
score2:gameScore,
score3:savedSN.score2,
score4:savedSN.score3};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);
cleanUp();
gotoAndStop(1);
// Go to the start menu
} else if ((gameScore > savedSN.score3 || savedSN.score3 == "-") &&
gameScore != 0) {
trace("Score 3");
savedSN = { // Set the date the savedSN varible will have
name1:savedSN.name1,
name2:savedSN.name2,
name3:PName.text,
name4:savedSN.name3,
score1:savedSN.score1,
score2:savedSN.score2,
score3:gameScore,
score4:savedSN.score3};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);

cleanUp();
gotoAndStop(1); // Go to the start menu
} else if ((gameScore > savedSN.score4 || savedSN.score4 == "-") &&
gameScore != 0) {
trace("Score 4");
savedSN = { // Set the date the savedSN varible will have
name1:savedSN.name1,
name2:savedSN.name2,
name3:savedSN.name3,
name4:PName.text,
score1:savedSN.score1,
score2:savedSN.score2,
score3:savedSN.score3,
score4:gameScore};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);
cleanUp();
gotoAndStop(1); // Go to the start menu
}
}


I cannot find where the error is.. Hope anybody can help. Thanks.



Read more

stackoverflow.comm



File object can't find the file when there is one [android help]


File object can't find the file when there is one



In my app After user clicks on a button ,the download manager starts to download a file from internet and saving it to the internal sd card using this code:



void startDownload()
{
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
download_req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(PersianReshape.reshape("Downloading"))
.setDescription(PersianReshape.reshape("currently downloading the file..."))
.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().getAbsolutePath() , packageId + ".sqlite");
download_ID = mgr.enqueue(download_req);
}


After it is downloaded, I plan to check its existance everytime app runs with this code:



String DatabaseAddress =
Environment.getExternalStorageDirectory().getAbsolutePath() +
"/ee.sqlite";
File file = new File(DatabaseAddress);
Log.d("PATH File: ", DatabaseAddress);
if (file.exists()){
Toast.makeText(getApplicationContext(), "found", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "not found", Toast.LENGTH_SHORT).show();
}


Now when I run this code it returns "not found" message whereas the file is already there (I checked its existance using a file manager).


the device I test on is nexus 7 and path used in saving the download file is: /storage/emulated/0/ee.sqlite


ee.sqlite is the filename of downloaded file.


/storage/emulated/0/ is the default path returned by app


Permissions added to manifest for this code are:







Q: Why does file.exists() returns false when there is a file?



Read more

stackoverflow.comm



Disable checkbox if X are checked in android [android help]


Disable checkbox if X are checked in android



I have 15 CheckBox and I must to stuck user when he checks more than 5 CheckBox. Is it possible? I used the method OnCheckedChangeListener to know if an item was checked... but I don't know how to make a limit after 5 items selected. See what I've tried to do below:


I instante my integer:



int lengthBox = 15;
int lenghtMax = 5;


I select all my View in onCreate():



View[] tagsItem = new View[] {
findViewById(R.id.TagsCheckAA),
findViewById(R.id.TagsCheckBB),
findViewById(R.id.TagsCheckCC),
findViewById(R.id.TagsCheckDD),
findViewById(R.id.TagsCheckEE),
findViewById(R.id.TagsCheckFF),
findViewById(R.id.TagsCheckGG),
findViewById(R.id.TagsCheckHH),
findViewById(R.id.TagsCheckII),
findViewById(R.id.TagsCheckJJ),
findViewById(R.id.TagsCheckKK),
findViewById(R.id.TagsCheckLL),
findViewById(R.id.TagsCheckMM),
findViewById(R.id.TagsCheckNN),
findViewById(R.id.TagsCheckOO)
};


I create 15 CheckBox:



final CheckBox[] tagsCheck = new CheckBox[lengthBox];


Create the method (and it's here where I don't know what to do exactly):



OnCheckedChangeListener checker = new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton cb, boolean b) {
if(tagsCheck[0].isChecked() || tagsCheck[1].isChecked() ||
tagsCheck[2].isChecked() || tagsCheck[3].isChecked() ||
tagsCheck[4].isChecked() || tagsCheck[5].isChecked() ||
tagsCheck[6].isChecked() || tagsCheck[7].isChecked() ||
tagsCheck[8].isChecked() || tagsCheck[9].isChecked() ||
tagsCheck[10].isChecked() || tagsCheck[11].isChecked() ||
tagsCheck[12].isChecked() || tagsCheck[13].isChecked() ||
tagsCheck[14].isChecked()) {
if(lenghtCount < 5){
// How can I get the String of the CheckBox
// which just checked?
String tags = (String) tagsCheck[].getText();
Toast.makeText(getApplicationContext(),
tags + " checked", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),
"Limit reached!!!", Toast.LENGTH_SHORT).show();
}
}
}
};


After this, I set my View id to my CheckBox and call the method:



for(int i = 0; i < lengthBox; i++) {
tagsCheck[i] = (CheckBox) tagsItem[i];
tagsCheck[i].setOnCheckedChangeListener(checker);
}


Can someone point me in the right way, please?


Thanks, any help will be appreciate.



UPDATE:


I found an inelegant way with an if(tagsCheck[0].isChecked() || ...). But I have still a problem: how can I get the CheckBox which just checked? Cause of my if(), I don't know how can I do this.


Thanks!



Read more

stackoverflow.comm



MediaRecorder crash [android help]


MediaRecorder crash




Very beginner in Android/Java, coming from C and Symbian, I started from the Hellworld example to try to display the sound level (the project is to record this level in a text file for hours). This code is written in the MainActivity file, as a method inside the MainActivity Class :



public void GetAFlevel(View view) throws IllegalStateException, IOException {
float audiolevel = 0, maxal = 0;
MediaRecorder mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null");
mRecorder.prepare();
mRecorder.start();
for (int i = 0; i < 1000; i++) {
audiolevel = mRecorder.getMaxAmplitude();
if (audiolevel > maxal)
maxal = audiolevel;
}
EditText editText1 = (EditText) findViewById(R.id.editText1);
editText1.setText(String.valueOf(maxal));
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}


The result is a crash of the application on the target :



11-17 00:23:09.859: D/AndroidRuntime(22096): Shutting down VM

11-17 00:23:09.859: W/dalvikvm(22096): threadid=1: thread exiting with uncaught exception (group=0x40018578)

11-17 00:23:09.921: E/AndroidRuntime(22096): FATAL EXCEPTION: main

11-17 00:23:09.921: E/AndroidRuntime(22096): java.lang.IllegalStateException: Could not execute method of the activity


No crash if I remove the following MediaRecorder functions : setAudioSource, setOutputFormat, setAudioEncoder, setOutputFile, prepare, start and stop, but getMaxAmplitude returns 0, of course.


As soon as I add only setAudioSource (normaly the only necessary for getMaxAmplitude), crash !


Any idea ?


Thanks in advance.



Read more

stackoverflow.comm



Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...