error in android studio package android.veiw does not exist - android

1 it showing a error package android.veiw does not exist in my android studio
2 when i add a buuton and use onClick
package com.example.batman.buttoncheck;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.veiw.Veiw;
import android.view.MenuItem;
public class Button_MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button__main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_button__main, menu);
return true;
}
public void buttononClick(Veiw v){
//do nothing
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Typo.
Change
import android.veiw.Veiw
to
import android.view.View
And similarly
public void buttononClick(Veiw v)
to
public void buttononClick(View v)

Related

Manifest attribute in Android using Eclipse

I'm new in android programming and I encountered some error while following some tutorials on Youtube.
Manifest attribute 'minSdkVersion' is set to 'R'. Integer is expected.
Here's the code:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here's the AndroidManifest.xml
|
Again Im just a beginner, please help thanks!
You need to change minSdkVersion version as below
android:minSdkVersion="21"

Back button in android studio

Hi guys i try to implement a back button in android studio that will bring me back to my previous activity.I manage to display the button on my app but when i press the button it just don't function .There is no error in my program.
package com.example.window8.myfriend;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class design extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_design);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.images);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_image, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.home) {
Intent intent = new Intent(getApplicationContext(),Systemtime.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Back button should be android.R.id.home & below line will be used to return to parent activity.
NavUtils.navigateUpFromSameTask(this);

app chrashing on imageview rotation

Hi guys i am new on android developing and i am trying to rotate an imageview.
The problem comes when (obviously) i push the button and the app close itself
Code java:
package comad.exampleaaaa.vittoriodaadntico.bottiglia3;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity6 extends AppCompatActivity {
public ImageView bottiglia;
public Button gira;
#Override
protected void onCreate(Bundle savedInstanceState) {
gira=(Button)findViewById(R.id.btn_roll);
bottiglia=(ImageView)findViewById(R.id.bottiglia);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6);
}
public void rollOnClick(View v){
RotateAnimation anim=new RotateAnimation(0,360,20,20,20,20);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
bottiglia.startAnimation(anim);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity6, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
error log :
http://imgur.com/H2Phsvf
You call methods in wrong order:
#Override
protected void onCreate(Bundle savedInstanceState) {
gira=(Button)findViewById(R.id.btn_roll); // This
bottiglia=(ImageView)findViewById(R.id.bottiglia); // And this
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6); // Should come after this
}
Here you search for views before you set content view. You should set your view, and only then search for widgets. Otherwise there is no view in which your widgets could be found, so both gira and bottiglia are nulls:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6);
gira=(Button)findViewById(R.id.btn_roll);
bottiglia=(ImageView)findViewById(R.id.bottiglia);
}

how to slide down the action bar in android to display something like coversation

i want to display the conversation between me and admin when i dragged the action bar. since i was new to android programming i dont know how to slide the action bar also. the following code is a decoy(dummy) code, coz its not letting me to post the question without sample code. please help me to drag or slide down the action bar to display conversation. thank you.
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.view.View;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt=(Button)findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
{
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Why this program is not working in Android Virtual Device?

WelcomeActivity:
package com.emdad.androidapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
public class WelcomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
findViewById(R.id.androidButton).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent=new Intent(WelcomeActivity.this, GameActivity.class);
startActivity(intent);
}
});
setContentView(R.layout.activity_welcome);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.welcome, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
GameActivity:
package com.emdad.androidapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class GameActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.game, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
When it was run in Android Virtual Device, it replied "Unfortunately, it has stopped." What is the problem?
You should move
setContentView(R.layout.activity_welcome);
before
findViewById(R.id.androidButton).setOnClickListener(new OnClickListener() {
Corrected:
setContentView(R.layout.activity_welcome);
findViewById(R.id.androidButton).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent=new Intent(WelcomeActivity.this, GameActivity.class);
startActivity(intent);
}
});

Categories

Resources