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.

at java.util.Arrays$ArrayList.get(Arrays.java:75)


AD MOB

Problem in Android application:

E/AndroidRuntime(416): FATAL EXCEPTION: main
E/AndroidRuntime(416): java.lang.IndexOutOfBoundsException
E/AndroidRuntime(416): 	at java.util.Arrays$ArrayList.get(Arrays.java:75)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:351)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
E/AndroidRuntime(416): 	at android.widget.Spinner.makeAndAddView(Spinner.java:192)
E/AndroidRuntime(416): 	at android.widget.Spinner.layout(Spinner.java:151)
E/AndroidRuntime(416): 	at android.widget.Spinner.onLayout(Spinner.java:115)


Solution: check code for set and get selection

// Spinner _spin1 contain only  49 items 
// you can set max 48 ( range 0 - 48)
// 50 is IndexOutOfBoundsException
_spin1.setSelection(50);

397LW NO topic_id




AD

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


365

layout-sw600dp values-sw600dp Android example of use | layout-sw600dp-values-sw600dp-android-example-of-use


Why the app selects data from basic layout folder if smallest width is higher then the number in folder name?
Example 1
layout-sw600dp values-sw600dp (smallest width sw for data usage from this folder is 600dp density independent pixel!!!!!)
Device screen resolution is 1200 x 900 px (pixel) Wow, app to be select data from sw600dp folder! Realy?
DPI of device screen - dot per inch (pixel per inch) is 480 pixel it is wery important number!


  1. App selects smallest dimension of screen. In our case 900 px
    Medium screen have 160 dpi (The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen.).


  2. App calculate ratio 480 / 160 = 3 (The conversion of dp units to screen pixels: px = dp * (dpi / 160))


  3. App calculate smallest dimesnion of screen in dp 900 / 3 = 300 dip or dp (density independed pixel).


  4. App selects data from basic values and layout folder because sw600dp is greater than 300dp.





In our case smallest dimension of screen must be at least 1800 real - physical pixels (1800 px / 3 ratio(dpi/160) = 600 dp (dip density independend pixels) to be used data from folders values-sw600dp and layout-sw600dp.


Example 2 see Example 1 abouve
Device: Nexus 7 (2012) selected from Android Studio tool layout editor
Resolution: 800x1280 px
DPI: tvdpi (approximately 213dpi)
Ratio: 1.33 (213 / 160)
Smallest width in px: 800
Convert px to dp: 601.5 (800 / 1.33)
Result:Smallest width is 601.5dp The App to be used data from folders values-sw600dp and layout-sw600dp.
329

Eclipse ADT plugin not recent graphical layout editor | eclipse-adt-plugin-not-recent-graphical-layout-editor


Click to Android version combobox - drop down menu and select your version, which just using (have instaled). For example: You updated ADT by SDK manager, but forget to update Android version. You can use lower version from drop down menu, which using your project, or do update of Android by SDK manager.
adt-plugin-not-recent
218

How to save the state of Activity - Android | how-to-save-the-state-of-activity-android


onSaveInstanceState, onRestoreInstanceState , save preferences

int mCurrentPhotoIndex = 0;
   @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putInt("photo_index", mCurrentPhotoIndex);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        mCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
        super.onRestoreInstanceState(savedInstanceState);
    }

// or save preferences for new start of Activity in onStop
//onCreate or onResume or onStart etc.
public void loadPreferences() {
		SharedPreferences settings = getSharedPreferences(F.PREFERENCES_NAME, 0);
		mCurrentPhotoIndex = settings.getInt("mCurrentPhotoIndex",mCurrentPhotoIndex);
	// String_sOtazka = settings.getString("_sOtazka", _sOtazka);


}
// onStop
public void savePreferences() {
		SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt("mCurrentPhotoIndex", mCurrentPhotoIndex);
                // String, boolean, float ...
		// editor.putString("mButton1", mButton1.getText().toString());

		editor.commit();

}

59

Relative layout RelativeLayout Android example | relative-layout-relativelayout-android-example


xml RelativeLayout Android example:

Eclipse graphical xml layout editor
[caption id="attachment_896" align="alignleft" width="261" caption="Relativelayout Eclipse graphical editor"]relativelayout-graphical-editor-eclipse[/caption]


res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/idLabel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Enter word"/>
    <EditText
        android:id="@+id/idEntry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_below="@id/idLabel"/>
    <Button
        android:id="@+id/idOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/idEntry"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text="OK" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/idOk"
        android:layout_alignTop="@id/idOk"
        android:text="Cancel" />
</RelativeLayout>
222

android - OnClickListener must override a superclass method | android-onclicklistener-must-override-a-superclass-method


The method onClick(DialogInterface, int) of type new DialogInterface.OnClickListener(){} must override a superclass method.

Try this:
Right click on project
Select Properties
In open dialogue select Java compiler
Set Enable project specific settings
Set Compiler compliance level to 1.6

project-properties-eclipse

java-compiler-settings-eclipse




Editace: 2014-02-15 20:32:53
Počet článků v kategorii: 397
Url:at-java-util-arraysarraylist-getarrays-java75

AD
11 Share
Share
Tweet