Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Java Basic Rules


AD MOB


// file name MyFirstClass.java

import java.util.*;
import java.lang.Math;
import java.io.*;
import javax.swing.*;

public class MyFirstClass{ // start of program
  public static void main(String[] args) { // basic  function main

// variables and calculation
int a=2;
int b=3;
int c=Integer.parseInt(JOptionPane.showInputDialog(" Put number: ", "1"));
System.out.println("Number is: "+c);
System.out.println(a+" * "+b+" = "+(a*b));
System.out.println("a^3 "+Math.pow(a,b));

//array
int[] array_my=new int[10];
array_my[0]=3;
array_my[1]=5;
System.out.println("Number of elements "+array_my.length+" 1 + 2 element of array "+(array_my[0]+array_my[1]));

//strings
String txt="Quick red fox";
String txt2=JOptionPane.showInputDialog("Write text: ", "word");
System.out.println("Text is: "+txt2);
String[] count_of_word=txt.split(" ");
System.out.println("Length: "+txt.length()+" Count of words "+count_of_word.length);
System.out.println(txt +" -> "+txt.replace("red","brown"));
System.out.println("First 5 chars of string is: "+ txt.substring(0,5));

//for a if
for(int i=0; i<10;i++){
	if(i==3)System.out.println("i equal "+i);
	}

// file
try {
  File soubor=new File("some_file.txt");
  if(!soubor.exists()){
	System.out.println("File dont exist");
  }
  else { // utf-8 encoding
    BufferedReader in1 = new BufferedReader(new InputStreamReader(new FileInputStream(soubor),"UTF-8"));
    BufferedWriter out1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("zapis.txt"),"UTF-8"));
    String str;
      while ((str = in1.readLine())!=null){
        System.out.println(str);
        out1.write(str+"

"); } in1.close(); out1.close(); } } catch(IOException e){System.out.println("Error " + e);} // dir File pathName = new File("some_dir"); String[] fileNames = pathName.list(); if(pathName.exists()) System.out.println("Name of first file in \"some_dir\": "+fileNames[0]); else System.out.println("dir not exist"); //function int nResult = calculateMyFc(3,5); System.out.println("Result of function: "+nResult); } // end of function main // new function , you can add to end MyFc = my function public static int calculateMyFc(int a, int b){ return (a+b); } } // end of class of program

397LW NO topic_id




AD

Další témata ....(Topics)


333

SimpleCursorAdapter deprecated | simplecursoradapter-deprecated


Constructor SimpleCursorAdapter is deprecated.
If using api 11 and above, you can try add last parameter 0.


Cursor cursor = managedQuery(...........,,,,);
// Specify the columns we want to display in the result
            String[] from = new String[] { KEY_WORD,
                                           KEY_DEFINITION };

            // Specify the corresponding layout elements where we want the columns to go
            int[] to = new int[] { R.id.word,
                                   R.id.definition };
// deprecated 
 SimpleCursorAdapter words =
            new SimpleCursorAdapter(this,
                    R.layout.result, cursor, from, to);
// working
 SimpleCursorAdapter words =
            new SimpleCursorAdapter(this,
                    R.layout.result, cursor, from, to, 0); // to, 0!!!!


//working in Fragment
SimpleCursorAdapter  mAdapter = new SimpleCursorAdapter(getActivity(),
                android.R.layout.simple_list_item_2, null,
                new String[] { "name", "age" }, // cursor parameters
                new int[] { android.R.id.text1, android.R.id.text2 }, 0);


98

Activity Lifecycle if button Home pressed Android example | activity-lifecycle-if-button-home-pressed-android-example


If on Android emulator home button pressed.

// button home presssed
19:37:06.727: INFO/ActivityManager(60): Starting: 
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] 
flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 60

19:37:06.807: INFO/onSaveInstanceState(339): onSaveInstanceState()
19:37:06.848: INFO/onPause(339): onPause()
19:37:07.968: INFO/onStop(339): onStop()


Diagram of Activity lifecycle if button HOME pressed

life_cycle_button_home_pressed
396

ADB restart device every time Android Studio | adb-restart-device-every-time


Android Studio ADB restart mobile device from USB every time if RUN of DEBUG button pressed

Try to close the mobile application on your device completely before starting again from Android Studio.
Close every fragment.
The problem occurs when the application has multiple fragments.

Date: 13.07.2020 - 08:23
317

Unable to execute dex: Multiple dex files define Eclipse Android | unable-to-execute-dex-multiple-dex-files-define-eclipse-android


Try each step separately:


  1. Restart Eclipse

  2. Clean project and rebuild

  3. Create a new project and try it if the problem persists, if no move copy project to other folder, delete project from workspace , create new project same name and copy java, xml etc. files to new project

  4. Close Eclipse, backup folder c:\Users\myName\workspace\.metadata and delete it. Restart Eclipse try again import project to workspace


  5. Re-installing the Android Developer Tools


  6. Re-installing Eclipse - rename old folder with Android to Android_old, create new folder C:\Program Files\Android and copy new Eclipse with sdk into new folder


  7. Created a new project importing from the file system


  8. Created a new project from subversion



326

phpbb forum mobile friendly theme style | phpbb-forum-mobile-friendly-theme-style


- download any mobile styles for example //www.artodia.com/phpbb-styles/mobile/
- unzip style into your forum style folder for example all art_mobile folder copy into 0:/myweb/forum/styles/
- folow instalation istructions //www.artodia.com/phpbb-styles/mobile/tutorials/mobile-detection/
- check url result on https://www.google.com/webmasters/tools/mobile-friendly


Editace: 2013-12-09 11:06:19
Počet článků v kategorii: 397
Url:java-basic-rules

AD
11 Share
Share
Tweet