My application will not display anything? just a blank white page? - android

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

Related

The intent passing one data twice(actually should pass 2 data)

I'm new in android and I just write a test app that should take the texts of the two buttons & change the text of them to each other in the new activity with intent.
but when I run the app and click the first button, it goes to second activity and in the second activity it just showing only the text of that button I just clicked on for both 2 buttons! actually, it should change the text of buttons to each other.(I mean the text of button 1 should display in button 2 and vice versa)
I check every question about the intent here, but my case is waired!!! because it seems everything is right! also, I check the code many times, I don't realize what's wrong!!!!
Thanks.
Here is the code:
MainActivity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button buttonone,buttontwo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void changeText(View view){
buttonone=(Button) view;
buttontwo=(Button) view;
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("button1text",buttonone.getText().toString());
intent.putExtra("button2text",buttontwo.getText().toString());
startActivity(intent);
}
}
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:id="#+id/activity_main"
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="com.example.myb.assignment.MainActivity">
<Button
android:text="One"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="35dp"
android:layout_marginTop="46dp"
android:id="#+id/buttonone"
android:onClick="changeText"/>
<Button
android:text="Two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="59dp"
android:id="#+id/buttontwo"
android:onClick="changeText"
android:layout_alignBaseline="#+id/buttonone"
android:layout_alignBottom="#+id/buttonone"
android:layout_alignParentEnd="true" />
</RelativeLayout>
SecondActivity
public class SecondActivity extends Activity {
Button button1,button2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
#Override
public void onResume(){
super.onResume();
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
String intentData1=getIntent().getExtras().getString("button1text");
String intentData2=getIntent().getExtras().getString("button2text");
button1.setText(intentData2);
button2.setText(intentData1);
}
}
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/button1"
android:layout_alignParentEnd="true"
android:layout_marginEnd="59dp"
android:id="#+id/button2"
/>
<Button
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="34dp"
android:layout_marginTop="46dp"
android:id="#+id/button1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myb.assignment">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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"> </activity>
</application>
</manifest>
In your MainActivity, in changeText(),
buttonone=(Button) view;
buttontwo=(Button) view;
These two lines assign the same button view, to both the buttons.
Insted of this, I recommend doing the following in your onCreate() method after setContentView();
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
And remove those two lines in changeText().

java.lang.IllegalStateException : Could not find a method onClick handler with id_button

I want to ask about my project. I create a class (RestoranView.class) which has 3 buttons: Menu, Maps and Rating. Two of them (Maps and Rating) work well but when I clicked button "Menu", it didn't work and the logcat showed those errors. I have implemented the same code. Could you help me to fix the error? Thanks in advance.
Logcat error
01-12 22:04:28.543: E/AndroidRuntime(25625): FATAL EXCEPTION: main
01-12 22:04:28.543: E/AndroidRuntime(25625): java.lang.IllegalStateException: Could not find a method MenuClick(View) in the activity class com.example.hellojson.RestoranView for onClick handler on view class android.widget.Button with id 'button_menu'
01-12 22:04:28.543: E/AndroidRuntime(25625): at android.view.View$1.onClick(View.java:3685)
01-12 22:04:28.543: E/AndroidRuntime(25625): at android.view.View.performClick(View.java:4222)
RestoranView.java
ackage com.example.hellojson;
public class RestoranView extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.restoran_view);
// intent from RestoranView.class to the Map.class
public void MenuCLick (View v) {
Intent menu = new Intent(RestoranView.this, TabMenu.class);
menu.putExtra(Restoran.id_restoran_tags, resto.getId_restoran());
startActivity(menu);
}
// intent from RestoranView.class to the Map.class
public void MapsClick(View v) {
Intent maps = new Intent(RestoranView.this, Map.class);
maps.putExtra(Restoran.nama_tags, resto.getNama());
maps.putExtra(Restoran.latitude_tags, resto.getLatitude());
maps.putExtra(Restoran.longitude_tags, resto.getLongitude());
maps.putExtra(Restoran.desc_tags, resto.getDesc());
startActivity(maps);
}
// intent from RestoranView.class to the Rating.class
public void RatingClick(View v) {
Intent rating = new Intent(RestoranView.this, Rating.class);
rating.putExtra(Restoran.id_restoran_tags, resto.getId_restoran());
rating.putExtra(Restoran.nama_tags, resto.getNama());
startActivity(rating);
}
}
RestoranView.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/nama_restoran_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dip"
android:paddingTop="5dip"
android:text="Nama Restoran"
android:textColor="#color/Navy"
android:textSize="25sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/image_restoran_view"
android:layout_width="275dp"
android:layout_height="241dp"
android:layout_gravity="center_horizontal"
android:paddingTop="10dip"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/alamat_restoran_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:text="Alamat :"
android:textColor="#color/Navy"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/phone_restoran_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:text="Phone : "
android:textColor="#color/Navy"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/deskripsi_restoran_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:text="Deskripsi"
android:textColor="#color/Navy"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:onClick="MenuClick"
android:text="Menu" />
<Button
android:id="#+id/button_maps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:onClick="MapsClick"
android:text="Maps" />
<Button
android:id="#+id/button_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:onClick="RatingClick"
android:text="Rating" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellojson"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.hellojson.SplashScreen"
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=".MenuUtama" >
</activity>
<activity android:name=".AboutMedan" >
</activity>
<activity android:name=".AllVenue" >
</activity>
<activity android:name=".TabMenu" >
</activity>
<activity android:name=".Map" >
</activity>
<activity android:name=".RestoranView" >
</activity>
<activity android:name=".Rating" >
</activity>
<activity android:name=".Search" >
</activity>
</application>
</manifest>
Could not find a method MenuClick(View) in the activity class com.example.hellojson.RestoranView for onClick handler on view class android.widget.Button with id 'button_menu'
Change
public void MenuCLick (View v)
to
public void MenuClick (View v) { // l small
coz you have
android:onClick="MenuClick" // its MenuClick not MenuCLick
And as tobor said
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.restoran_view);
} // missing }
You didn't close your onCreate method... add the missing } before MenuClick.
In my case I wasnt adding the View parameter in the onClick function
changed
public void sendMessage()
to
public void sendMessage(View v)
In my case, on android lolly, remove the theme attribute from the xml and put the theme in android manifest. It should start working.

Android: sending parameters between two activities failed

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);

Thread exiting with uncaught exception (group=0x4001d800) FATAL EXCEPTION:Main

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.

Android eclipse. Error when running my application

I cant get my application to work, but theres no error message in the development.
Im trying to learn how to link my page to another page.
TMactivity page 1.
public class TmActivity extends Activity {
private ImageButton NewPage;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
this.NewPage = (ImageButton)this.findViewById(R.id.widget38);
this.NewPage.setOnClickListener(new OnClickListener() {
public void onClick(View WebView) {
Intent i = new Intent(TmActivity.this, New.class);
startActivity(i);
}
});
}
}
// Page 2:
public class WebView extends Activity {
public class New extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
}
}
}
//first xml:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="#+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:id="#+id/widget37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_x="4dp"
android:layout_y="387dp" />
<ImageButton
android:id="#+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="69dp"
android:layout_y="386dp" />
<ImageButton
android:id="#+id/widget39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="151dp"
android:layout_y="386dp" />
<ImageButton
android:id="#+id/widget40"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="242dp"
android:layout_y="383dp" />
<TextView
android:id="#+id/widget43"
android:layout_width="wrap_content"
android:layout_height="47px"
android:background="#FF0000"
android:text="Teknikmagasinet"
android:textSize="20sp"
android:typeface="sans"
android:textStyle="bold"
android:textColor="#FFFF00"
android:layout_x="74dp"
android:layout_y="11dp" />
<TextView
android:id="#+id/widget44"
android:layout_width="203px"
android:layout_height="30px"
android:text="nyheter"
android:textColor="#FFFF00"
android:layout_x="34dp"
android:layout_y="77dp" />
<ImageView
android:id="#+id/widget45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff33cc00"
android:layout_x="44dp"
android:layout_y="143dp" />
<TextView
android:id="#+id/widget46"
android:layout_width="wrap_content"
android:layout_height="47px"
android:background="#ffcc6600"
android:text=" emil bergstrlm han är kung "
android:hint="phuong"
android:layout_x="13dp"
android:layout_y="255dp" />
</AbsoluteLayout>
// second xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
package="tm.com"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<ImageButton
android:id="#+id/widget38"
android:layout_width="150dp"
android:layout_height="wrap_content" />
<Button
android:text="Second Page"
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
sting xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, TmActivity!</string>
<string name="app_name">Tm.com</string>
<string name="main_title">My Main Title</string>
</resources>
Thank you for any help!
//remove this life from your second activity
public class WebView extends Activity {
and register New in your manifest.xml
If I understand correctly, you're trying to open a new activity from an already running activity (Switching your page)? Try this.
Activity Main.java :
package tm.com
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TmActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button butn = (Button) findViewById(R.id.button1);
butn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(TmActivity.this, New.class);
startActivityForResult(intent, 0);
}
});
}
}
Layout Main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="#+id/button1" android:text="name" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</RelativeLayout>
In Application Manifest : *Modify the manifest in the application bracket to look like this.
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".TmActivity"
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=".New"></activity>
</application>

Categories

Resources