I'm still very new to this so the solution is probably obvious.
Any way I'm trying to make the buttons in this app open new activities but when I run it, forcecloses. Does anyone know what's wrong? I was going to use something called list view but that didn't use the XML I made for the class.
package com.example.musicbynumbers;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
public class MainMenu extends Activity implements View.OnClickListener {
Button majScales, minHarm, minMel;
ImageButton mainMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
mainMenu = (ImageButton) findViewById(R.id.imagelogo);
majScales = (Button) findViewById(R.id.majorscalesb);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.imagelogo:
Intent i = new Intent(MainMenu.this, MainMenu.class);
startActivity(i);
break;
case R.id.majorscalesb:
Intent j = new Intent(MainMenu.this, majorScales.class);
startActivity(j);
break;}
}
}
Layout:
<LinearLayout 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:orientation="vertical"
android:weightSum="80"
tools:context=".MainMenu"
>
<ImageButton
android:id="#+id/imagelogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight="10"
android:gravity="center" />
<Button
android:id="#+id/majorscalesb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Major Scales"
android:gravity="center" />
<Button
android:id="#+id/minormelodicb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Minor Melodic Scales"
android:gravity="center"/>
<Button
android:id="#+id/minorharmonicb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Minor Harmonic Scales"
android:gravity="center"/>
<Button
android:id="#+id/arpeggiosb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Arpeggios"
android:gravity="center" />
<Button
android:id="#+id/chromaticscalesb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Chromatic Scales"
android:gravity="center" />
<Button
android:id="#+id/contraryb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Contrary Motion"
android:gravity="center" />
<Button
android:id="#+id/aboutb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="About"
android:gravity="center"
>
</Button>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.musicbynumbers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.musicbynumbers.MainMenu"
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.example.musicbynumbers.majorScales"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.musicbynumbers.majorScales" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
fix your code by this
ImageButton mainMenu;
mainMenu = (ImageButton) findViewById(R.id.imagelogo);
UPDATE:
OK, I found the error. you forgot to set the OnClickListener for every Button or ImageButton
try this
majScales.setOnClickListener(this);
mainMenu.setOnClickListener(this);
For one thing you spelled the intent incorrectly.
Intent j = new Intent("com.exapmle.muscibynumbers.majorScales");
should be
Intent j = new Intent("com.example.musicbynumbers.majorScales");
For another, you have two applications defined.
Without the stack trace it's hard to know what else might be wrong.
Related
I am building my app and when I run it with emulator/my phone its crash before opening even. Here is the code:
Mainactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.example.marvelx.phonecall.MainActivity">
<Button
android:id="#+id/button"
android:onClick="send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="105dp"
android:text="Button" />
<EditText
android:id="#+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/button"
android:layout_alignParentTop="true"
android:layout_marginTop="68dp"
/>
<EditText
android:id="#+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/et1"
android:layout_below="#+id/et1"
android:layout_marginTop="37dp"
/>
<EditText
android:id="#+id/et3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/et2"
android:layout_below="#+id/et2"
android:layout_marginTop="32dp"
/>
</RelativeLayout>
androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.marvelx.phonecall">
<uses-permission android:name="android.permission.CALL_PHONE" />
<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>
MainActivity.java
package com.example.marvelx.phonecall;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText[] number;
#Override
protected void onCreate(Bundle savedInstanceState)
{
number= new EditText[3];
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
number[0]= findViewById(R.id.et1);
number[1]= findViewById(R.id.et2);
number[2]= findViewById(R.id.et3);
}
public void send(View v) {
Call();
}
int index = 0;
public void Call(){
String num = number[index].getText().toString();
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+num));
startActivity(intent);
}
}
I've tried rebuilding, cleaning the Project and research on Google, Stack, and Youtube without success.
Where i can also upload the Logcat?
Simply remove the <uses-permission android:name="android.permission.CALL_PHONE"/> from your MainActivity.xml file. I tested it on my side, and it fixed the problem.
Also, consider changing Intent.ACTION_CALL into Intent.ACTION_DIAL. The dial action doesn't require the permission you would remove.
This question already has answers here:
ActivityNotFoundException while sending email from the application
(3 answers)
Closed last month.
android manifest code
Email.java
email.xml
files
are
below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shubham.myapplication" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action
android:name="com.example.shubham.myapplication.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.shubham.myapplication.MENU"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="#string/app_name" >
</activity>
<activity
android:name=".TextPlay1"
android:label="#string/app_name" >
</activity>
<activity
android:name=".Email"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.content.Intent.ACTION_SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Email.java
package com.example.shubham.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Email extends Activity implements View.OnClickListener {
EditText personsEmail, intro, personsName, stupidThings, hatefulAction,
outro;
String emailAdd, beginning, name, stupidAction, hatefulAct, out;
Button sendEmail;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.email);
initializeVars();
sendEmail.setOnClickListener(this);
}
private void initializeVars() {
// TODO Auto-generated method stub
personsEmail = (EditText) findViewById(R.id.etEmails);
intro = (EditText) findViewById(R.id.etIntro);
personsName = (EditText) findViewById(R.id.etName);
stupidThings = (EditText) findViewById(R.id.etThings);
hatefulAction = (EditText) findViewById(R.id.etAction);
outro = (EditText) findViewById(R.id.etOutro);
sendEmail = (Button) findViewById(R.id.bSentEmail);
}
public void onClick(View v) {
// TODO Auto-generated method stub
convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
String emailaddress[] = { emailAdd };
String message = "Well hello "
+ name
+ " I just wanted to say "
+ beginning
+ ". Not only that but I hate when you "
+ stupidAction
+ ", that just really makes me crazy. I just want to make
you "
+ hatefulAct
+ ". Welp, thats all I wanted to chit-chatter about, oh and"
+ out
+ ". Oh also if you get bored you should check out your
stupidity"
+ '\n' + "PS. I think I love you... :(";
Intent ourIntent = new Intent(Intent.ACTION_SEND);
ourIntent.putExtra(Intent.EXTRA_EMAIL,emailaddress);
ourIntent.putExtra(Intent.EXTRA_SUBJECT,"I judgsjug you");
ourIntent.putExtra(Intent.EXTRA_TEXT,message);
startActivity(ourIntent);
}
private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated()
{
// TODO Auto-generated method stub
emailAdd = personsEmail.getText().toString();
beginning = intro.getText().toString();
name = personsName.getText().toString();
stupidAction = stupidThings.getText().toString();
hatefulAct = hatefulAction.getText().toString();
out = outro.getText().toString();
}
}
email.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:weightSum="100" android:layout_height="match_parent">
<ScrollView android:layout_weight="30" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:text="Email address(es):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etEmails">
</EditText>
<TextView android:text="Hateful Intro:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etIntro"></EditText>
<TextView android:text="Person's name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="#+id/etName">
</EditText>
<TextView android:text="Stupid Things that this Person does"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etThings"></EditText>
<TextView android:text="What you want to do to this person:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etAction"></EditText>
<TextView android:text="Hateful Outro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etOutro"></EditText>
</LinearLayout>
</ScrollView>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_weight="40"
android:layout_height="fill_parent">
<Button android:text="Send Email" android:id="#+id/bSentEmail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></Button>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_weight="30"
android:layout_height="fill_parent">
<AnalogClock android:id="#+id/analogClock1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></AnalogClock>
</LinearLayout>
</LinearLayout>
here a runtime exception occured
as
987-1987/com.example.shubham.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.shubham.myapplication, PID: 1987
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 (has clip) (has extras) }
Make sure you have any email application installed on the mobile device you are testing on and
replace
ourIntent.putExtra(Intent.EXTRA_TEXT,message);
with
ourIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(message);
Same problem has been answered here.
I'm doing a simple Android application (a measure converter) and I'm using two activities: the first activity is the main application and the second activity it's for display the result.
When I put the value, select the type of conversion (yards to centimetres, for example) and click on the result button, the result only appears in the first activity (not the second activity).
This is my code:
ActivityMain.java
package displayinsecact.project;
import android.app.*;
import android.content.Intent;
import android.os.*;
import android.view.*;
import android.widget.*;
public class ActivityMain extends Activity{
private EditText etxt;
private TextView txtViewRes;
private CheckBox chkBoxYarCen, chkBoxCenYar, chkBoxYarMet, chkBoxMetYar, chkBoxYarPie, chkBoxPieYar;
private ConversorMedidas current;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initialUISetup();
txtViewRes=(TextView)findViewById(R.id.txtViewRes);
}
public void initialUISetup(){
etxt=(EditText)findViewById(R.id.etxt);
txtViewRes=(TextView)findViewById(R.id.txtViewRes);
chkBoxYarCen=(CheckBox)findViewById(R.id.chkBoxYarCen);
chkBoxCenYar=(CheckBox)findViewById(R.id.chkBoxCenYar);
chkBoxYarMet=(CheckBox)findViewById(R.id.chkBoxYarMet);
chkBoxMetYar=(CheckBox)findViewById(R.id.chkBoxMetYar);
chkBoxYarPie=(CheckBox)findViewById(R.id.chkBoxYarPie);
chkBoxPieYar=(CheckBox)findViewById(R.id.chkBoxPieYar);
}
public void exchange(View v){
double aux=0;
if(chkBoxYarCen.isChecked()==true){
current=new convYarCen();
aux=current.yardasCentimetros(Double.parseDouble(etxt.getText().toString()));
}
if(chkBoxCenYar.isChecked()==true){
current=new convYarCen();
aux=current.yardasMetros(Double.parseDouble(etxt.getText().toString()));
}
if(chkBoxYarMet.isChecked()==true){
current=new convYarMet();
aux=current.yardasMetros(Double.parseDouble(etxt.getText().toString()));
}
if(chkBoxMetYar.isChecked()==true){
current=new convYarMet();
aux=current.yardasCentimetros(Double.parseDouble(etxt.getText().toString()));
}
if(chkBoxYarPie.isChecked()==true){
current=new convYarPie();
aux=current.yardasCentimetros(Double.parseDouble(etxt.getText().toString()));
}
if(chkBoxPieYar.isChecked()==true){
current=new convYarPie();
aux=current.yardasMetros(Double.parseDouble(etxt.getText().toString()));
}
txtViewRes.setText(String.valueOf(aux));
}
String contenido;
public void showThirdActivity(View v){
contenido=txtViewRes.getText().toString();
Intent i=new Intent(this, ResultadoActivity.class);
i.putExtra("resultado", contenido);
startActivity(i);
}
}
ResultActivity.java
package displayinsecact.project;
import android.app.Activity;
import android.os.*;
import android.widget.*;
public class ResultadoActivity extends Activity{
TextView tvDatosRecibidos;
String cadena;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.resultado);
tvDatosRecibidos=(TextView)findViewById(R.id.tvDatosRecibidos);
Bundle recogerDatos=getIntent().getExtras();
cadena=recogerDatos.getString("resultado");
tvDatosRecibidos.setText(cadena);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is the second activity" />
<TextView
android:id="#+id/txtViewData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Input Data"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/etxt"><requestFocus></requestFocus>
</EditText>
<!--
chkBoxYarCen, chkBoxCenYar, chkBoxYarMet, chkBoxMetYar, chkBoxYarPie, chkBoxPieYar;
-->
<CheckBox
android:id="#+id/chkBoxYarCen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yards to Centimetres"
/>
<CheckBox
android:id="#+id/chkBoxCenYar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Centimetres to Yards"
/>
<CheckBox
android:id="#+id/chkBoxYarMet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yards to Metres"
/>
<CheckBox
android:id="#+id/chkBoxMetYar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Foot to Yards"
/>
<CheckBox
android:id="#+id/chkBoxYarPie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yards to Foots"
/>
<CheckBox
android:id="#+id/chkBoxPieYar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Foots to Yards"
/>
<!-- Botones -->
<Button
android:id="#+id/btnOpe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exchange"
android:onClick="exchange"
/>
<TextView
android:id="#+id/txtViewRes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resultado"
/>
resultado.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Datos recibidos de la actividad anterior"
/>
<TextView
android:id="#+id/tvDatosRecibidos"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="displayinsecact.project"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ActivityMain"
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:label="Resultado Activity"
android:name=".Resultadoctivity">
<intent-filter >
<action android:name=".Resultadoctivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
Sorry for the inconvenient.
Change your code in first activity like this
Intent i=new Intent(this, ResultadoActivity.class);
Bundle b =new Bundle();
b.putString("resultado", contenido);
i.putExtras(b);
startActivity(i);
I made an app it was working perfectly I also had a imageview with scrolling pictures.
All I did was add a button and after that when I run it the app will not show anything. just a plain white blank screen. I have a feeling it could be an intent issue but they seem to be fine with no errors.
Like I said the intents were working fine. I've checked every bit of my code but doesn't seem to load up my Main activity layout.(xml)
Unfortunately I didn't keep a backup . Also LogCat Doest not say anything whatsoever
`
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Welcome to iStyle Events"
android:textColor="#FF9500"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<Button
android:id="#+id/Gallery"
style="?android:attr/buttonStyleSmall"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:textColor="#FF9500"
android:text="#string/Gallery" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:textColor="#fafad2"
android:text="hello"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/Services"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignTop="#+id/linearLayout1"
android:layout_toLeftOf="#+id/linearLayout1"
android:textColor="#FF9500"
android:text="#string/Services" />
<Button
android:id="#+id/Contact"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView1"
android:layout_alignTop="#+id/linearLayout1"
android:layout_toRightOf="#+id/linearLayout1"
android:textColor="#FF9500"
android:text="#string/Contact" />
`
.java =
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Main extends Activity {
Button service;
Button gallery;
Button contact;
protected void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
service = (Button)findViewById(R.id.Services);
service.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent (Main.this, servicesActivity.class);
startActivity(intent);
}
});
gallery = (Button)findViewById(R.id.Gallery);
gallery.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent1 = new Intent (Main.this, galleryActivity.class);
startActivity(intent1);
}
});
contact = (Button)findViewById(R.id.Contact);
contact.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent2 = new Intent (Main.this, contactActivity.class);
startActivity(intent2);
}
});
}
}
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.istyleevents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.istyleevents.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="galleryActivity"></activity>
<activity android:name="servicesActivity"></activity>
<activity android:name="contactActivity"></activity>
</application>
</manifest>
You have a 1 behind the method onCreate. Is it just a copy-paste mistake ? If I remove it, you layout is shown
You have a typo on your onCreate method. It's written as onCreate1. If that's how it's written in the java file and not just a copt&paste error here, that may be your problem.
Check your android:layout_width and android:layout_height and make sure they are not cover other content is my guesss please post the xml file
So I've been working on a soundboard app for my kids. This is my first app so as you can imagine I very nearly have no idea what I'm doing (noob) so I'm apologizing in advance :-). I'm not sure where my problem is but my splash screen runs no problem but when it tries to load the next activity it force closes. i'm going to include my manifest the java file that is supposed to play the audio and the layout for the buttons which are clickable images. Thanks in advance! Also I would like to set it up where the buttons could play a random sound that relates to the image using soundpool but again with the noobness. I'm not really familiar at all with the errors but I'm seeing java.land.classcastexception: android.widget.imageview as the reason the mymenu activity isn't starting. Hope that helps.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pnl.thebasics"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/sssicon"
android:label="#string/app_name" >
<activity android:label="#string/app_name" android:name=".myMain">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".myMenu">
<intent-filter>
<action android:name="com.pnl.thebasics.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
package com.pnl.thebasics;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class myMenu extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// Hide the title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Go full screen
final Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.menu);
//these are the buttons that play sounds
//button 1 (sponge bob)
final MediaPlayer mpButtonClick1 = MediaPlayer.create(this, R.raw.sb1);
Button bSpongebob = (Button) findViewById(R.id.sbbutton);
bSpongebob.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
mpButtonClick1.start();
}
});
//button 2 (patrick)
final MediaPlayer mpButtonClick2 = MediaPlayer.create(this, R.raw.pat1);
Button bPatrick = (Button) findViewById(R.id.patbutton);
bPatrick.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
mpButtonClick2.start();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/sbbutton"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_weight="50"
android:clickable="true"
android:src="#drawable/sbbuttonimage" />
<ImageView
android:id="#+id/patbutton"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_weight="50"
android:clickable="true"
android:src="#drawable/patbuttonimage" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/mrcrabsbutton"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_weight="50"
android:clickable="true"
android:src="#drawable/mrcrabsbuttonimage" />
<ImageView
android:id="#+id/squidwardbutton"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_weight="50"
android:clickable="true"
android:src="#drawable/squidwardbuttonimage" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout03"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/planktonbutton"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_weight="50"
android:clickable="true"
android:src="#drawable/planktonbuttonimage" />
<ImageView
android:id="#+id/garybutton"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_weight="50"
android:clickable="true"
android:src="#drawable/garybuttonimage" />
</LinearLayout>
</LinearLayout>
Your Java code is expecting to find a Button object in your layout:
Button bSpongebob = (Button) findViewById(R.id.sbbutton);
But your layout declares that widget to be an ImageView:
<ImageView
android:id="#+id/sbbutton"
An ImageView isn't a Button, and when your Java code tries to force it to be a Button you get the java.lang.ClassCastException.
Two choices to fix:
1) Change your Java code to use ImageView.
2) Change your layout to declare a Button.
Either will accept the click listener you're trying to set. Don't forget you need to make this fix for both widgets in your app.