While cycle loop in Java example
While cycle Java basic example with array of strings.
MainClass.java
MainClass.java
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
int i = 0;
while ( i < arrayOfString.length ){
System.out.println(arrayOfString[i]);
i++;
}
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
String sFileContent = readFile("myfile.txt",StandardCharsets.UTF_8);
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return encoding.decode(ByteBuffer.wrap(encoded)).toString();
}
// write file
String sOut = "text blah hello world etc.";
writeToFile(sOut"someName.txt");
static void writeToFile(String sB,String name) {
String folder = ("c:\\folder\");
File f = new File(folder+ name);
BufferedWriter writer = null;
writer = new BufferedWriter( new OutputStreamWriter(
new FileOutputStream( folder+name),"UTF-8"));
writer.write( sB);
if ( writer != null)
writer.close( );
}
AlertDialog like MessageBox by WinApi:
If error: Unable to add window -- token null is not for an application
try change get Context.
If error: Unable to add window -- token null is not for an application
try change get Context.
// you can put this text into some function body or case in switch statement
new AlertDialog.Builder(this)
.setMessage("Hello boys!!!")
.setPositiveButton("OK", null)
.show();
Context context = getApplicationContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select font size");
final CharSequence[] chsSize= { "Small", "Medium", "Large"};
builder.setSingleChoiceItems(chsSize, 0 /*sel.item*/,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(context, "Hello from dialog!!!", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
Windows 7 64-bit version.
Eclipse 64-bit - Java was started but returned exit code=13
Solution:
Download and install 64-bit version of JDK
//www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Eclipse 64-bit - Java was started but returned exit code=13
Solution:
Download and install 64-bit version of JDK
//www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Hide module - open dialog: File > Project Structure Ctrl + Alt + Shift + S
Hide module: in opened Dialog select module which will hidden and click on minus (left upper corner)
If module is hidden, you can permanetly delete module from disk. But if you want using module in future, copy module into other folder (not into AndroidProjects folder and his subbfolders) and delete module permanetly from project and disc. Right mouse click on module and select from menu Delete.
If you want import the backup copy to project, use: File>New>Import mudule
Hide module: in opened Dialog select module which will hidden and click on minus (left upper corner)
If module is hidden, you can permanetly delete module from disk. But if you want using module in future, copy module into other folder (not into AndroidProjects folder and his subbfolders) and delete module permanetly from project and disc. Right mouse click on module and select from menu Delete.
If you want import the backup copy to project, use: File>New>Import mudule
private void dialogModeFC() {
try {
final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.select_dialog)
//.setItems(
.setSingleChoiceItems(R.array.select_dialog_items, -1
, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
/* User clicked so do some stuff
<item>Happy New Year</item>
<item>Merry Christmas</item>
<item>I Love You</item>
*/
String[] items = getResources().getStringArray(R.array.select_dialog_items);
// list with boolean variables - which is true
// for (int i = 0; i < _listMode.size(); i++) {
// _listMode.set(i, false);
// }
// _listMode.set(which, true);
dialog.dismiss();
// new AlertDialog.Builder(MainActivity.this)
// .setMessage("You selected: " + which + " , " + items[which])
// .show();
}
})
.create();
alertDialog.show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG)
.show();//("dialogModeFC", e.getMessage().toString());
}
}// end dialogModeFC
Editace: 2011-10-04 08:57:30
Počet článků v kategorii: 396
Url:while-cycle-loop-in-java-example