I'm new to android development and I'm currently working on building a pretty basic application. I want 'button1' to open a new activity. Looked around online and I can't work out what I'm doing wrong!
Java:
package com.testtest.herro;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FullscreenActivity extends Activity
{
Button button1, saved;
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
{
setContentView(R.layout.activity_fullscreen);
button1 = (Button) findViewById (R.id.button1);
};
};}
I'm getting the following errors on the public void onCreate method:
The findViewById line has this error:
-ids cannot be resolved or is not a field.
XML:
<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:background="#FFFFFF"
android:orientation="vertical"
tools:context="com.testtest.herro.FullscreenActivity" >
<View
android:layout_width="1dp"
android:layout_height="30dp" >
</View>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="center"
android:text="Idea Cloud"
android:textSize="45sp"
android:typeface="monospace" >
</TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="center"
android:text=""
android:textSize="45sp"
android:textStyle="bold" >
</TextView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:background="#FFFFFF"
android:orientation="vertical" >
<View
android:layout_width="1dp"
android:layout_height="30dp" >
</View>
<Button
android:layout_width="250sp"
android:layout_height="100sp"
android:layout_gravity="center"
android:text="New"
android:textSize="20sp"
android:typeface="monospace"
android:id="@+id/button1" >
</Button>
<View
android:layout_width="1dp"
android:layout_height="50dp" >
</View>
<Button
android:layout_width="250sp"
android:layout_height="100sp"
android:layout_gravity="center"
android:text="Saved"
android:textSize="20sp"
android:typeface="monospace"
android:id="@+id/savedB" >
</Button>
</LinearLayout>
</LinearLayout>
Any help is greatly appreciated! Thanks.
Your super
call is outside the method. This:
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
{
...
}
should be:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
...
}
In general, if you start seeing lots of errors, it's worth looking at the first line containing an error - that's probably the cause. Also, save and compile often, so you can tell where you've made a mistake and fix it quickly.
Also note that you don't need semi-colons after method or class declarations - I would remove them as a matter of style.
Ideally, use @Override
too, to get the compiler to check that you're really overriding a method:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
...
}
See more on this question at Stackoverflow