Saturday, March 7, 2015

Android :Unable to instantiate activity ComponentInfo

Unable to instantiate activity ComponentInfo





You may be trying to find the view before onCreate() which is incorrect.

public class MainActivity extends Activity {

  ImageView mainImage = (ImageView) findViewById(R.id.imageViewMain); //incorrect

  @Override
  protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  }
  ...
}

Sunday, March 1, 2015

Android : Creating a new Activity (new screen)

Creating a new Activity


Creating new activity and navigating onclick button (Explicit Activity)
    1. goto res/layout > rt ck > select "new xml file" and "new_layout"
    2. Add objects,make modifications to new layout xml file in graphical view
    3. Manifest file : add below code  inside "<application> </application>"
   
            <activity android:name=".new_Activity">
 
       
    4. Goto src/package > rt ck and select new>Class
    5. give name as "new_Activity" ,ck OK and add below code in "new_Activity"
   
   
        import android.app.Activity;
        public class  new_Activity extends Activity
        {
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.new_layout);
                }
        }


    6. Goto activity_main.xml ,create a button and in properties>view>On click-"method_name" and save
    7. Goto Mainactivity>add below method inside the class :
        public void method_name(View V)
        {
            Intent intent=new Intent(this,new_Activity.class);
            startActivity(intent);
        }

Android : Change SDK in Android Studio

Change SDK in Android Studio


To do this, on the menu choose File -> Project Structure. Select the Libraries option and click the green + to add your library.