250 views

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
Posted in Bugs, warnings, errors, Eclipse | Comments Off
261 views

Ad baner without GoogleAdMobAdsSdkAndroid-6.4.1 Android example

First: AdView is in XML file

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="MY_AD_UNIT_ID"
    ads:adSize="BANNER"/>
 
// onResume
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("TEST_DEVICE_ID")
    .build();
adView.loadAd(adRequest);

Second: Using AdView in Fragment with LinearLayout
Resolve error in ADT Graphical layout editor:
The following classes could not be instantiated:
- com.google.android.gms.ads.AdView

// layout in xml file
    <LinearLayout
        android:id="@+id/layout"
              android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
 
// java class with fragment in Fragment class or in Activity class
private static AdView adView;
        @Override
		public void onResume(){  
                super.onResume();
                 try {
                	 // in xml is empty layout
					adView = new AdView(getActivity());
					adView.setAdUnitId("ca-app-pub-626/638103xxxxxxx");
					adView.setAdSize(AdSize.BANNER);  
 
                	                LinearLayout layout = (LinearLayout)getView() .findViewById(R.id.layout);
					layout.addView(adView);
 
					AdRequest adRequest = new AdRequest.Builder().build();   
					adView.loadAd(adRequest);
 
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
        }

More about:
https://developers.google.com/mobile-ads-sdk/docs/admob/android/play-migration?hl=it

Posted in Android Examples Code | Tagged , , , | Comments Off
197 views

Importing google-play-service library project to workspace issue

Try two way in Eclipse IDE:

1.) Import the library project into your Eclipse workspace.
Click File > Import,
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
If project not visible with checkbox try next step as see below.

2.) Click
File > New > Other
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.

Posted in Android Examples Code, Eclipse | Tagged | Comments Off
207 views

Every fragment must have an empty constructor Android Java Class

You have to add constructor!

    public static class YourFragment extends Fragment {
    //you have to add constructor!!!!!	
    public YourFragment(){}
 
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.activity_main, container, false);
 
            return view;
        }   
 
    }
Posted in Android Examples Code | Tagged | Comments Off
336 views

Difference between logical operators and or Java

Basic difference remember it!!!
if(TRUE && TRUE && TRUE) return TRUE otherwise FALSE

if(FALSE || FALSE || FALSE) return FALSE otherwise TRUE

Logical operator and &&
If all conditions/operands is TRUE return TRUE, otherwise return FALSE

if( true and true and true){ 
  // return true - do something
}
int a = 6;
if(a == 6 && a == 6 ) {
 // if TRUE
 // true && true return true, do something
}
 
if(a == 6 && a == 5){
  // nothing, not attended
}else{
  // true && false return false, do something
}

Logical operator or ||
The logical OR operator (||) returns the boolean value true if either or both operands is true and returns false otherwise.
If one operands is TRUE, condition is TRUE:

if(FALSE OR FALSE OR TRUE) return TRUE
if(FALSE OR TRUE OR FALSE) return TRUE
if(FALSE OR FALSE OR FALSE) return FALSE
 
int a = 6;
if(a==6 || a==5){ // TRUE || FALSE return TRUE
  //if return TRUE
  //one from operadns is TRUE return true,  do something
}
 
if(a==5 || a==4){ // FALSE || FALSE return FALSE
 // not attended
}else{
 //if return FALSE, do something
}

rev

Posted in Android Examples Code | Tagged , | Comments Off
518 views

Import project Android Eclipse

Import a new Android project for example downloaded from internet via Eclipse into project folder.

  1. Right click into projects explorer in Eclipse and select Import
  2. Android
  3. Existing Android Code Into Workspace
  4. Root Directory (select folder of downloaded project)
  5. Check your downloaded project
  6. Check Copy project into Workspace
  7. Finish (press)
Posted in Android Examples Code, Eclipse | Tagged | Comments Off
1,014 views

findViewById in onCreate returns NULL when using Fragment

Call findViewById from onCreateView

public class MainActivity extends ActionBarActivity {
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
 
		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.containerMoje, new PlaceholderFragment()).commit();
		}
 
	}
 
 
	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {
		public PlaceholderFragment() {
		}
 
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main, container,
					false);
			if (container == null) {
		        return null;
		    }
 
 
			 TextView mText;
			mText = (TextView)rootView.findViewById(R.id.idText);
			mText.setText("Hello from fragment_main");
 
			return rootView;
		}
	}
}

res\layout
activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/containerMoje"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="cz.okhelp.autoskola.MainActivity"
    tools:ignore="MergeRootFrame" />

fragment_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="cz.okhelp.autoskola.MainActivity$PlaceholderFragment" >
 
    <TextView
        android:id="@+id/idText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
 
</RelativeLayout>
Posted in Android Examples Code | Tagged , | Comments Off
641 views

Windows set Environment Variables – Java path

How set JAVA path to Environment Variables on Windows (7)
Select Start menu > Computer > System Properties > Advanced System Settings(properties).
Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example

 C:\Program Files\Java\jdk1.8.0_05
Posted in Eclipse | Tagged | Comments Off
734 views

Where Eclipse stored Settings and Templates Java Code

C:\documents\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs
Posted in Eclipse | Comments Off
1,049 views

ADT Bundle 22.6.2 have memory leak.

If I trying
android-sdk_r22.6.2-windows.zip
adt-bundle-windows-x86_64-20140321.zip
and open xml layout graphic editor and xml layout file
memory continues to grow to crashes Eclipse

https://developer.android.com/sdk/index.html

I have to install old version adt-bundle-windows-x86-20131030.zip
what working fine.
I had to delete .metadata folder in workspace if I want open old version ADT

Posted in Bugs, warnings, errors, Eclipse | Comments Off
1,049 views