//Errors in Javascript code
//Made a few modifications to word-unscrambler code but it is not working
function myFunction() {
var x = document.getElementById("myText").value;
document.getElementById("demo").innerHTML = x;
answer = randomWord(demo);
$(document).ready(function() {
$("#word").text(randomize(answer));
});
$(".guess").bind("change paste keyup", function() {
if ($(this).val().toUpperCase() == answer){
answer = randomWord(demo);
$("#word").text(randomize(answer));
$(".guess").val("");
$(".solution").text("");
}
});
$(".solve").on("click", function(event){
$(".solution").text(answer);
});
}
function randomWord(words) {
//return words[Math.floor(Math.random()*words.length)].toUpperCase();
myFunction();
<p id="demo"></p>
return demo;
}
function randomize (word){
var newWord = ' ';
for (var i in word){
var randLetter = word.charAt(Math.floor(Math.random()*word.length));
newWord = newWord.concat(randLetter);
word = word.slice(0, word.indexOf(randLetter)) +
word.slice(Number(word.indexOf(randLetter)+1),word.length);
}
return newWord;
}
//There is no action after clicking the submit button.
Syntax errors everywhere.
Use Chrome's Developer Console so you can see the errors
There really are a lot of mistakes. Try to review everything carefully again, or as advised earlier to put it on a site or program so that you highlight errors.
As other users told you, there are some syntax that's not alright. Use an IDE first fix your syntax, and then, debug it. Also some indentation won't hurt anybody. My recommendation would be to use an IDE to help you. Here's a simple one that runs online without installing anything:
https://playcode.io
Related
Hello, i have downloaded the Torch source code from cyanogen repository and i have this problem:
1º I put the code in a empty project in Eclipse
2º I havent errors and the code compile correctly
3º I run the app in my device (Nexus One) and work well all buttons and options, but when i press in "On" button for active i get a error and the app crash.
Debugging i have seen the following:
For active flash i have put a "1" in file "/sys/devices/platform/flashlight.0/leds/flashlight/brightness" (If i put a "1" manually with terminal the flash is active correctly)
In code, we have this:
public class FlashDevice {
private static final String DEVICE = "/sys/devices/platform/flashlight.0/leds/flashlight/brightness";
...
public synchronized void setFlashMode(int mode) {
try {
if (mWriter == null) {
mWriter = new FileWriter(DEVICE);
}
int value = mode;
switch (mode) {
case STROBE:
value = OFF;
break;
case DEATH_RAY:
value = useDeathRay ? DEATH_RAY : HIGH;
break;
}
mWriter.write(String.valueOf(value));
mWriter.flush();
mFlashMode = mode;
if (mode == OFF) {
mWriter.close();
mWriter = null;
}
} catch (IOException e) {
throw new RuntimeException("Can't open flash device: " + DEVICE, e);
}
}
public synchronized int getFlashMode() {
return mFlashMode;
}
}
Click to expand...
Click to collapse
I get this error in line "mWriter = new FileWriter(DEVICE);":
java.io.FileNotFoundException: /sys/devices/platform/flashlight.0/leds/flashlight/brightness (Permission denied)
Someone know the cause????
Try using the original source code from the repository by
Code:
svn checkout http://n1torch.googlecode.com/svn/trunk/ n1torch-read-only
and importing it as a project into eclipse.
Hi!
I am loading a text to TextView from a file on a webpage with my Android app but the problem is that the text is full of ASCII characters, so when the text is loaded to the TextView, I can't see any of these ASCII characters or it shows me a "?" within a black square.
My question is, how can I convert an ASCII character to string?
Thanks for helping.
adamhala007 said:
Hi!
I am loading a text to TextView from a file on a webpage with my Android app but the problem is that the text is full of ASCII characters, so when the text is loaded to the TextView, I can't see any of these ASCII characters or it shows me a "?" within a black square.
My question is, how can I convert an ASCII character to string?
Thanks for helping.
Click to expand...
Click to collapse
Code:
char c = 'e';
String s = String.valueOf(c);
Are you sure that there's no other problem with your code? It doesn't sound like a conversion error.
nikwen said:
Code:
char c = 'e';
String s = String.valueOf(c);
Are you sure that there's no other problem with your code? It doesn't sound like a conversion error.
Click to expand...
Click to collapse
I don't know, but here is my code:
Code:
TextView textMsg;
final String textSource = "PATH/TO/MY/.CRL/FILE";
BufferedReader reader;
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
I have forgotten to mention that my file where I load the text from has .crl extension. I have tried the code you posted, but the problem still remains. So it shows me still the "?" within the black squares.
adamhala007 said:
I don't know, but here is my code:
Code:
TextView textMsg;
final String textSource = "PATH/TO/MY/.CRL/FILE";
BufferedReader reader;
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
I have forgotten to mention that my file where I load the text from has .crl extension. I have tried the code you posted, but the problem still remains. So it shows me still the "?" within the black squares.
Click to expand...
Click to collapse
Could you please post an example file?
Can CRL files really be read using a Buffered reader? Aren't the encrypted?
nikwen said:
Could you please post an example file?
Can CRL files really be read using a Buffered reader? Aren't the encrypted?
Click to expand...
Click to collapse
OK. I know why you cannot do it that way:
*.crl files are no text files. When you open them in a browser that supports it, you might see the entries. However, it is no plain text. (You might be able to read some parts, but it is not completely text.)
Proof:
I downloaded a CRL file on my Linux machine.
The way to get its content if it is a textfile is to use the cat command:
Code:
cat <path>
That way I am able to read parts of the file, but most characters aren't real characters. (Things like your ?s.)
So we need another way to do that.
---------- Post added at 09:34 AM ---------- Previous post was at 09:30 AM ----------
You can find classes for reading CRLs in the java.security.cert package: http://developer.android.com/reference/java/security/cert/package-summary.html
EDIT: This seems to be the best tutorial I found so far: http://www.javaworld.com/javaworld/jw-03-2001/jw-0316-howto.html
I found that tutorial with some code snippets: http://jce.iaik.tugraz.at/sic/Support/Technical-Articles/Parsing-Large-CRLs-in-Java
Another tutorial related to CRLs: http://www.nakov.com/blog/2009/12/0...rify-chain-and-verify-clr-with-bouncy-castle/
XDA is an awesome place for developers to share their knowledge and help each other, no question about it.
However, in my opinion, one of the flaws that prevent the app development forums from being more popular is the
Code:
tags.
Indeed, these tags do not provide syntax highlighting, and when people start pasting their whole Java class, the lack of proper indentation plus the lack of syntax highlighting leaves us with a very off-putting chunk of code, and even if you intend to help in the first place, having to go through this unreadable code can discourage many.
I was ranting about this in the [URL="http://forum.xda-developers.com/showpost.php?p=49938207&postcount=1976"]xda suggestions & feedback thread[/URL], when someone pointed-out the existence of the [B][PHP][/B] tags, which provide syntax highlighting for php, and, the syntaxes of PHP and Java being somewhat similar, they also do the trick for Java.
[FONT="Garamond"][I]Example:[/I][/FONT]
[PHP]
package com.androguide.recovery.emulator;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import android.util.Log;
public class CMDProcessor {
private final String TAG = getClass().getSimpleName();
private static final boolean DEBUG = false;
private Boolean can_su;
public SH sh;
public SH su;
public CMDProcessor() {
sh = new SH("sh");
su = new SH("su");
}
public SH suOrSH() {
return canSU() ? su : sh;
}
public boolean canSU() {
return canSU(false);
}
public class CommandResult {
private final String resultTag = TAG + '.' + getClass().getSimpleName();
public final String stdout;
public final String stderr;
public final Integer exit_value;
CommandResult(final Integer exit_value_in) {
this(exit_value_in, null, null);
}
CommandResult(final Integer exit_value_in, final String stdout_in,
final String stderr_in) {
exit_value = exit_value_in;
stdout = stdout_in;
stderr = stderr_in;
if (DEBUG)
Log.d(TAG, resultTag + "( exit_value=" + exit_value
+ ", stdout=" + stdout + ", stderr=" + stderr + " )");
}
public boolean success() {
return exit_value != null && exit_value == 0;
}
}
public class SH {
private String SHELL = "sh";
public SH(final String SHELL_in) {
SHELL = SHELL_in;
}
private String getStreamLines(final InputStream is) {
String out = null;
StringBuffer buffer = null;
final DataInputStream dis = new DataInputStream(is);
try {
if (dis.available() > 0) {
buffer = new StringBuffer(dis.readLine());
while (dis.available() > 0) {
buffer.append("\n").append(dis.readLine());
}
}
dis.close();
} catch (final Exception ex) {
Log.e(TAG, ex.getMessage());
}
if (buffer != null) {
out = buffer.toString();
}
return out;
}
public Process run(final String s) {
Process process = null;
try {
process = Runtime.getRuntime().exec(SHELL);
final DataOutputStream toProcess = new DataOutputStream(
process.getOutputStream());
toProcess.writeBytes("exec " + s + "\n");
toProcess.flush();
} catch (final Exception e) {
Log.e(TAG,
"Exception while trying to run: '" + s + "' "
+ e.getMessage());
process = null;
}
return process;
}
public CommandResult runWaitFor(final String s) {
if (DEBUG)
Log.d(TAG, "runWaitFor( " + s + " )");
final Process process = run(s);
Integer exit_value = null;
String stdout = null;
String stderr = null;
if (process != null) {
try {
exit_value = process.waitFor();
stdout = getStreamLines(process.getInputStream());
stderr = getStreamLines(process.getErrorStream());
} catch (final InterruptedException e) {
Log.e(TAG, "runWaitFor " + e.toString());
} catch (final NullPointerException e) {
Log.e(TAG, "runWaitFor " + e.toString());
}
}
return new CommandResult(exit_value, stdout, stderr);
}
}
public boolean canSU(final boolean force_check) {
if (can_su == null || force_check) {
final CommandResult r = su.runWaitFor("id");
final StringBuilder out = new StringBuilder();
if (r.stdout != null) {
out.append(r.stdout).append(" ; ");
}
if (r.stderr != null) {
out.append(r.stderr);
}
Log.d(TAG, "canSU() su[" + r.exit_value + "]: " + out);
can_su = r.success();
}
return can_su;
}
}
[/PHP]
Oddly enough, the [B][PHP][/B] tags also work for XML (while the [html] tags, that do exist, don't work):
[PHP]
<LinearLayout
android:id="@+id/contentLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="8dip"
android:layout_weight="90"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dip"
android:fontFamily="sans-serif-light"
android:textColor="#33B6EA"
android:textSize="22sp" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dip"
android:layout_marginRight="8dip"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:textColor="#232323"
android:maxLines="50"
android:textSize="16sp" />
</LinearLayout>
[/PHP]
This doesn't fix the indentation issues, but as you can see, the code is much more readable and welcoming.
By using the [B][PHP][/B] tags instead of the [strike][CODE][/strike] tags, you will be more likely to get answers to your questions involving code.
[B][SIZE="3"][CENTER]So Please, for the sake of the app development forums and the eyes of your readers:
USE THE [COLOR="RoyalBlue"][PHP][/COLOR] TAGS :victory:[/CENTER][/SIZE][/B]
[CENTER][I]Please raise awareness about this, suggest people who don't use the [B][PHP][/B] tags to use them, and together we'll make this app development forum a better place than it already is :good:[/I][/CENTER]
Whoa! Never knew about this. Nice find.
Wow, this is really cool! Thanks for finding. The only problem I have with the PHP tags is on mobile, tapatalk is obviously not supporting it at all:
SimplicityApks said:
Wow, this is really cool! Thanks for finding. The only problem I have with the PHP tags is on mobile, tapatalk is obviously not supporting it at all:
Click to expand...
Click to collapse
Too bad, thanks for reporting :good:
This obviously is just a workaround, xda could quite easily implement a dedicated syntax highlighting plugin for vBulletin as I suggested in the suggestions thread, but for the time being this is probably the closest thing we've got.
Androguide.fr said:
Too bad, thanks for reporting :good:
This obviously is just a workaround, xda could quite easily implement a dedicated syntax highlighting plugin for vBulletin as I suggested in the suggestions thread, but for the time being this is probably the closest thing we've got.
Click to expand...
Click to collapse
They've got it working way better with the CODE tags: Code syntax highlighting announcement!
Hi
How are you?
I have make simple android GUI to start privoxy and polipo binary
but my problem.How i can stop privoxy and polipo when press on stop button
i can get process id (PID) for privoxy and polipo using this code
Code:
public int findProcessIdWithPS(String str) throws IOException {
String readLine;
Runtime runtime = Runtime.getRuntime();
CharSequence name = new File(str).getName();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(runtime.exec("ps " + name).getInputStream()));
bufferedReader.readLine();
do {
readLine = bufferedReader.readLine();
if (readLine == null) {
return -1;
}
} while (!readLine.contains(name));
return Integer.parseInt(readLine.split("\\s+")[1]);
}
this code return the PID of process
then i have try kill process but not working with this code
Code:
Process process = Runtime.getRuntime().exec("kill -9 " + findProcessIdWithPS("privoxy"));
process.waitFor();
but this code not working with me
Please any help
Sorry of my English
Hello,
I am student in my final year doing a project based on android development. I am thinking of creating an application that scans all the installed application in the device and recover all the list of permission associated with the app.. I will then manually use the data to check the manifest files manually, so that I can flag up any app that has more permission than it should.
I am learning and just starting creating it in eclipse. But, any advice would greatly be appreciated as am new to this development world.
I am thinking of creating a GUI for the layout but how can I make it list all the installed application on the device before I can proceed into getting the permission.
Thank you.
You need to use the PackageManager
The solution is on stackoverflow (love that site), but since I can't post links yet, I'll simply give you the code (should work):
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}
Good luck!!
Edwin Bos said:
You need to use the PackageManager
The solution is on stackoverflow (love that site), but since I can't post links yet, I'll simply give you the code (should work):
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}
Good luck!!
Click to expand...
Click to collapse
Is it possible I can create it within a searchView so that it can search it and display the installed application. But, displayed the app in a scroll view as well.