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.

R cannot be resolved to a variable


AD MOB

Check your xml files in Eclipse Graphical Editor and fix problems.

r-cannot-be-resolved-android

Check project setup, right click on project, select properties, Java build path and
select correct Android version etc.
order-and-export-eclipse-android-project

Right click on project, Android Tools, Fix Project Properties

Menu Eclipse select Project ->Clean.

397LW NO topic_id




AD

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


395

Download file from root Android device Windows | download-file-from-root-android-device-windows


Download file from Android device using Android Studio

stackoverflow.com/questions/34603355/android-device-monitor-data-folder-is-empty

C:\Users\user>c:\Users\user\AppData\Local\Android\sdk\platform-tools\adb shell (press Enter)
shell@Kraft-A6000:/ $ 
shell@Kraft-A6000:/ $ su (Enter)
root@Kraft-A6000:/ #
root@Kraft-A6000:/ # su -c "chmod 777 /data" (Enter)
root@Kraft-A6000:/ # su -c "chmod 777 /data/data" (Enter)
root@Kraft-A6000:/ # su -c "chmod 777 /data/data/com.your_package" (Enter)
root@Kraft-A6000:/ # su -c "chmod 777 /data/data/com.your_package/databases" (Enter)
root@Kraft-A6000:/ # su -c "chmod 777 /data/data/com.your_package/databases/database_name.db" (Enter)


  • Open Android Studio -> Tools -> Android -> Android Device Monitor (meybe some message box, minimalize all windows to find message box - close message box )
  • Pull data from Explorer

Date: 13.07.2020 - 08:23
76

If, else if, else statement Java Android example | if-else-if-else-statement-java-android-example


if , else if, else statement with string as a switch statement in Java example source code.

MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "end" };
		for (int i = 0; i < arrayOfString.length; i++) {
			
			if (arrayOfString[i].equals("Hello"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("people"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("hello"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("world!"))
				System.out.println(arrayOfString[i]);
			else // default
				System.out.println("Default");
		}
	}
}
/*
Default
Hello
people
Default
hello
world!
Default 
 */
118

Android Api level - SDK version - how get Api level on device - sample | android-api-level-sdk-version-how-get-api-level-on-device-sample



import android.os.Build.VERSION;
//
int nSdkVersion = Integer.parseInt(Build.VERSION.SDK);
int nApiVersion = VERSION.SDK;






















Platform Version API Level
Android 4.0 14
Android 3.2 13
Android 3.1.x 12
Android 3.0.x 11
Android 2.3.4 10
Android 2.3.3 10
Android 2.3.2 9
Android 2.3.1 9
Android 2.3 9
Android 2.2.x 8
Android 2.1.x 7
Android 2.0.1 6
Android 2.0 5
Android 1.6 4
Android 1.5 3
Android 1.1 2
Android 1.0 1
277

How To Check New Version Of Application Android Code | how-to-check-new-version-of-application-android-code



private int _nVersionCode = 0;	
private boolean _bNewVersion = false;


// onCreate
     	 _nVersionCode   = this.getPackageManager()
     	.getPackageInfo(this.getPackageName(), 0).versionCode;
     	Log.d(String.valueOf(_nVersionCode), "versionCode");

// onStart loadPreferences
 public void loadPreferences() {
			//SharedPreferences settings = getSharedPreferences(F.PREFERENCES_NAME, 0);
			SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
		int nOldVersionCode =	settings.getInt("_nVersionCode",  0);// old vesion
		if(_nVersionCode > nOldVersionCode)
			_bNewVersion = true;
	}

// onDestroy savePreferences	
	public void savePreferences() {
			SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
			SharedPreferences.Editor editor = settings.edit();
			editor.putInt("_nVersionCode", _nVersionCode); // save current version code
			editor.commit();
	}


204

java.lang.NullPointerException: println needs a message | java-lang-nullpointerexception-println-needs-a-message


Problemi is in e.getMessage() what can return null and Log.e (String tag, String msg) will throws an new exception !!!!
Problem and solution:

      	try {
      		int [] i = {1};
      		int z = i[5];
      	} catch (ArrayIndexOutOfBoundsException e) {
      		String s = e.toString(); // s == java.lang.ArrayIndexOutOfBoundsException
                // try to testing String s for null value
      		if(s != null)
      		 Log.e("bla", s);
      		else 
      		 Log.e("bla", "My error text 1");
      		
      		String s2 = e.getMessage(); // s2 == null !!!!!!!
                // you need to testing String s2 for null value , or you get FATAL EXCEPTION: main
                // and application will be crashed
       		String s2 = e.getMessage(); // s2 == null !!!!!!!
      		if(s2 != null)
      		 Log.e("bla2", e.getMessage());
      		else 
      		 Log.e("bla2", "My error text 2");
     		
                // this is OK
      		e.printStackTrace();
      	}


LogCat:

E/bla(855): java.lang.ArrayIndexOutOfBoundsException

 E/bla2(855): My error text 2

 W/System.err(855): java.lang.ArrayIndexOutOfBoundsException
 W/System.err(855): 	at cz.okhelp.motion._MotionActivity.onTouchEvent(_MotionActivity.java:54)
 W/System.err(855): 	at android.app.Activity.dispatchTouchEvent(Activity.java:2099)
 W/System.err(855): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
 W/System.err(855): 	at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
 W/System.err(855): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
 W/System.err(855): 	at android.os.Handler.dispatchMessage(Handler.java:99)
 W/System.err(855): 	at android.os.Looper.loop(Looper.java:123)
 W/System.err(855): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
 W/System.err(855): 	at java.lang.reflect.Method.invokeNative(Native Method)
 W/System.err(855): 	at java.lang.reflect.Method.invoke(Method.java:507)
 W/System.err(855): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 W/System.err(855): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 W/System.err(855): 	at dalvik.system.NativeStart.main(Native Method)




Or you can using this code:

      	try {
      		int [] i = {1};
      		int z = i[5];
      	} catch (Exception e) {
      		
      		
      		StringBuilder sb = new  StringBuilder().append(e.getClass().getSimpleName()); 
          if  (e.getMessage() != null) { 
              sb.append("

"); sb.append(e.getMessage()); } Log.e("err", sb.toString()); // E/err(336): ArrayIndexOutOfBoundsException // this code write out all message Log.e("myError", "methodName", e); } // E/myError(371): methodName // E/myError(371): java.lang.ArrayIndexOutOfBoundsException // E/myError(371): at cz.okhelp.motion._MotionActivity.onTouchEvent(_MotionActivity.java:54) // E/myError(371): at android.app.Activity.dispatchTouchEvent(Activity.java:2099) // E/myError(371): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675) // E/myError(371): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194) // E/myError(371): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878) // E/myError(371): at android.os.Handler.dispatchMessage(Handler.java:99) // E/myError(371): at android.os.Looper.loop(Looper.java:123) // E/myError(371): at android.app.ActivityThread.main(ActivityThread.java:3683) // E/myError(371): at java.lang.reflect.Method.invokeNative(Native Method) // E/myError(371): at java.lang.reflect.Method.invoke(Method.java:507) // E/myError(371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) // E/myError(371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) // E/myError(371): at dalvik.system.NativeStart.main(Native Method)



Editace: 2014-02-15 20:14:31
Počet článků v kategorii: 397
Url:r-cannot-be-resolved-to-a-variable

AD
11 Share
Share
Tweet