I am a beginner in programming for Android, and am making a music and video player, which already programmed much of the program, but when the emulator executes I get the following error:
Unfortunately, FlagPlayer has stopped
I have done many researches on the subject but I can not find anything that solves my problem. I hope you can help me.
here is my main class:
package tcc.etec.FlagPlayer;
import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button btMusica;
private Button btArtista;
private Button btAlbum;
private Button btVideo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
acaobutton();
}
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) this);
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) this);
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) this);
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) this);
}
public void onClick(View v){
if (v.getId()==R.id.btmusica){
Intent intent = new Intent(MainActivity.this, ListaMusicaActivity.class);
}else if (v.getId()==R.id.btartista){
Intent intent = new Intent(MainActivity.this, ListaArtistaActivity.class);
}else if (v.getId()==R.id.btalbuns){
Intent intent = new Intent(MainActivity.this, ListaAlbumActivity.class);
}else if (v.getId()==R.id.btvideo){
Intent intent = new Intent(MainActivity.this, ListaVideoActivity.class);
}
}
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"
tools:context=".MainActivity" >
<Button
android:id="#+id/btmusica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:text="Musicas" />
<Button
android:id="#+id/btartista"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btmusica"
android:layout_alignBottom="#+id/btmusica"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:text="Artistas" />
<Button
android:id="#+id/btalbuns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="66dp"
android:text="Albuns" />
<Button
android:id="#+id/btvideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btalbuns"
android:layout_alignBottom="#+id/btalbuns"
android:layout_alignRight="#+id/btartista"
android:text="Videos" />
and AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tcc.etec.FlagPlayer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".tcc.etec.FlagPlayer.activity_main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".tcc.etec.FlagPlayer.ListaMusicaActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".tcc.etec.FlagPlayer.MusicPlayerActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Try to replacing your:
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) this);
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) this);
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) this);
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) this);
}
To:
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) getBaseContext());
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) getBaseContext());
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) getBaseContext());
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) getBaseContext());
}
Related
I'm making an android app on Android Studio. And I come out with a problem . When I click my ImageButton the app crashes instead of going to a new activity (Slide1)...
I dont know where I got it wrong .
Here is my MainActivity.java
package android.example.ptreinas;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
private ImageButton imageButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
openSlide1();
}
});
}
public void openSlide1(){
Intent intent = new Intent(this, Slide1.class);
startActivity(intent);
}
}
and my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center"
tools:context=".MainActivity"
android:background="#color/red">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="400px"
android:layout_gravity="center"
android:src="#drawable/gym" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Programa de treinos "
android:layout_gravity="center"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="80px"
android:layout_marginTop="50px"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Escolha o programa de treino mais adequado aos seus objetivos."
android:layout_gravity="center"
android:textAlignment="center"
android:layout_marginTop="50px"
android:textSize="50px"
android:textColor="#ffffff"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:src="#drawable/ic_right"
android:background="#drawable/roundcorner"
android:padding="50px"
android:layout_gravity="center"
android:layout_marginTop="150px"
/>
</LinearLayout>
</RelativeLayout>
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.example.ptreinas">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I dont know if you need the second activity (slide1.xml , Slide1.java) let me know
I need your help, thanks in advance .
replace this :
Intent intent = new Intent(this, Slide1.class);
by this:
Intent intent = new Intent(MainActivity.this, Slide1.class);
add your second activity in manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.example.ptreinas">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//add this line
<activity android:name=".Slide1"/>
</application>
I am trying to code an app where it connects to Bluetooth on the Main Activity Page and then on the Second Activity page it will turn on the silent ringer mode. Every time I click on the button to open up the next activity, the app closes down. There are no errors according to Android Studio.
Here is my SecondActivity.java file
package fonephree.fonephreeconnecttobluetooth;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class SecondActivity extends Activity {
Button button;
AudioManager audiomanager;
Context context;
TextView textview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
button = (Button)findViewById(R.id.button6);
textview = (TextView)findViewById(R.id.textView2);
context = getApplicationContext();
audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
textview.setText("Silent Mode Enable");
}
});
}
}
and here is my activity_second.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:background="#android:color/holo_orange_dark"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fonephree.fonephreeconnecttobluetooth.SecondActivity">
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Silent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button6"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp"
android:text="Silent Mode"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/phree"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
And just in case the error is in my AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fonephree.fonephreeconnecttobluetooth">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="#string/title_activity_second"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="fonephree.fonephreeconnecttobluetooth.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
EDIT
I fixed the code but now the app only shuts off when I press the button and it wasn't in silent mode before opening the app. The button just reinforces silent mode, it doesn't actually turn it on.
From the information what you have given, you are setting your XML to be activity_main, while the button6 and textview2 are defined in activity_second.xml
So your onCreate should like below to solve the problem
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
button = (Button)findViewById(R.id.button6);
textview = (TextView)findViewById(R.id.textView2);
context = getApplicationContext();
audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
textview.setText("Silent Mode Enable");
}
});
}
this is my manifest files:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iadmo.dahan"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal"
>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:name="com.iadmo.dahan.application.MyApplication"
android:icon="#drawable/appicon"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.iadmo.dahan.activity.WelcomeActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:clearTaskOnLaunch="false"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RecommendActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PersonalActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.LoginActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RegisterActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SortedActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ClassesActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SearchedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductDetailsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PerClassActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductCommentActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductSimpleInfoActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.CommentDetailsActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadingActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<service android:name="com.iadmo.dahan.service.DownloadService"/>
</application>
and this is the xml for layout of productdetailsActivity:
public class ProductDetailsActivity extends TabActivity {
private TabHost mHost;
private String appId, userId;
private ListView per_class_simple_info;
private List<BaseInfo> datas;
private DetailsAdapter adapter;
private TextView txtview1, txtview2;
private Button back;
private TextView title_name;
private Dialog dialog;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_productdetail);
MyApplication.getInstance().addActivity(this);
Bundle bundle = getIntent().getExtras();
appId = bundle.getString("appId");
userId = AppUtil.getString(getApplicationContext(), "userid", "");
initCompanents();
initViews();
initDatas();
Intent intent = new Intent();
intent.setAction("GOODID");
intent.putExtras(bundle);
getApplicationContext().sendBroadcast(intent);
initEvents();
}
#SuppressWarnings("deprecation")
private void initViews() {
back = (Button) findViewById(R.id.back);
title_name = (TextView) findViewById(R.id.title_name);
per_class_simple_info = (ListView) findViewById(R.id.per_class_simple_info);
mHost = this.getTabHost();
mHost.addTab(mHost.newTabSpec("mhost_job").setIndicator(txtview1)
.setContent(new Intent(this, ProductSimpleInfoActivity.class)));
mHost.addTab(mHost.newTabSpec("mhost_company").setIndicator(txtview2)
.setContent(new Intent(this, ProductCommentActivity.class)));
}
private void initCompanents() {
txtview1 = new TextView(this);
txtview1.setText("简介");
txtview1.setTextColor(getResources().getColor(R.color.white));
txtview1.setGravity(Gravity.CENTER);// 文字居中
txtview1.setTextSize(15);// 字体大小
txtview1.setPadding(15, 16, 15, 15);// 四周填充
txtview1.setBackgroundResource(R.drawable.tabhost_bg);
txtview2 = new TextView(this);
txtview2.setText("评论");
txtview2.setTextColor(getResources().getColor(R.color.black));
txtview2.setGravity(Gravity.CENTER);// 居中
txtview2.setTextSize(15);// 字体大小
txtview2.setPadding(15, 16, 15, 15);// 填充
txtview2.setBackgroundResource(R.drawable.tabhost_bg);
LayoutParams param1 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param1.setMargins(0, 10, 0, 0);
param1.weight = 1;// 权重
txtview1.setLayoutParams(param1);
LayoutParams param2 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param2.setMargins(0, 10, 0, 0);
param2.weight = 1;// 权重
txtview2.setLayoutParams(param2);
}
and this is the productSimpleInfoActivity's code:
public class ProductSimpleInfoActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simpleinfo);
MyApplication.getInstance().addActivity(this);
initViews();
registerReceivers();
initEvents();
}
this is the productDetail xml layout,i think this is right ,i tired it ,it worked,but today i tired again,it failed:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
</TabWidget>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/s_5"
android:background="#color/red_light" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Try the following code.It hopefully works.
main.xml file :
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabhost" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"></FrameLayout>
</LinearLayout>
</TabHost>
In Class File add this code in your onCreate():
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Personal.class);
spec = tabHost.newTabSpec("personal").setIndicator("Personal").setContent(intent);
tabHost.addTab(spec);
I am trying to get the ABOUT button to listen for a click, in order to go from a screen displaying three buttons and a picture, to another screen just displaying some text.
This is my Main java file (MainActivity.java)
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context cont = this;
Button aButton = (Button) findViewById(R.id.ab_button);
aButton.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(cont, AboutActivity.class);
startActivity(intent);
}
});
}
This is my second java file for the about button (AboutActivity.java):
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class AboutActivity extends Activity {
public void onCreate(Bundle about){
super.onCreate(about);
setContentView(R.layout.activity_about);
TextView briText = (TextView) findViewById(R.id.about_b2);
briText.setText("Goodie");
}
}
This is the main xml file that displays the picture and the buttons (activity_main.xml):
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about_b"
android:id="#+id/ab_button"
android:shadowColor="#8e2300"
android:background="#drawable/oval_button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/share_button"
android:id="#+id/share_button"
android:shadowColor="#8e2300"
android:onClick="shareActivity"
android:background="#drawable/oval_button"
And this is the xml file that displays the text (activity_about.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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#+id/back_to_work_rel">
<TextView android:text="#string/about_bac"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/about_b2" />
</RelativeLayout>
Manifest file (AndroidManifest.xml):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brian.eggalong" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AboutActivity"
android:parentActivityName=".MainActivity"
android:label="#string/about_bac">
</activity>
</application>
</manifest>
Every time I click the ABOUT button, nothing happens. Any help would be greatly appreciated.
Try to remove the background attribute of your button.
Otherwise you can try this
MainActivity.java
public void moveToAboutActivity(){
Intent i = new Intent(getApplicationContext(), AboutActivity.class);
startActivity(i);
}
activity_main.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about_b"
android:id="#+id/ab_button"
android:onClick="moveToAboutActivity"/>
good Luck
Ok, so, definetly the problem is that you need to put the activity in your manifest file like:
<activity
android:name=".activity.SplashScreen"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
i'm still new at learning java and this is my first android app and it used to work but now it just shows me an error whenever i try to run this page :
package com.ds.rssreader;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
public class StartingPoint extends ListActivity {
Button Add;
Button Delete;
public static String Menu[];
public static int Menu_counter = 0;
ListView Sites;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.starting);
Add = (Button) findViewById(R.id.Add);
Delete = (Button) findViewById(R.id.Delete);
Sites = (ListView) findViewById(R.id.list);
Add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenAddPage = new Intent("com.ds.rssreader.AddPage");
startActivity(OpenAddPage);
}
});
Delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenDeletePage = new Intent(
"com.ds.rssreader.DeletePage");
startActivity(OpenDeletePage);
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
and here it's Layout:
<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:padding="25dp"
tools:context="com.ds.rssreader.StartingPoint" >
<Button
android:id="#+id/Add"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Add"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/Delete"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Delete"
tools:ignore="HardcodedText" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/Add"
android:clickable="true"
tools:ignore="HardcodedText" >
</ListView>
</RelativeLayout>
and here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ds.rssreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:name="android.permission.INTERNET"
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.ds.rssreader.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.StartingPoint" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.AddPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.AddPage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.DeletePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.DeletePage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSFeed"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSFeed" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSHandler"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSHandler" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSItem"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSItem" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
the error causes the program to crash whenever i try to open this page and it says :
E/AndroidRuntime(1085): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ds.rssreader/com.ds.rssreader.StartingPoint}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
and when i try to debug it, it tells me that there is something's source not found
and for the record when i make any other page opens instead of this page it opens without any problems.
REMEMBER GUYS : I'm new in java so don't say big words try to simplify as much as you can
Thanks
In your layout, change:
android:id="#+id/list"
to
android:id="#id/android:list"
and, in your class change:
Sites = (ListView) findViewById(R.id.list);
to
Sites = (ListView) findViewById(android.R.id.list);