Nitrosolid
- Forum posts: 2
Mar 31, 2013, 6:54:11 PM via Website
Mar 31, 2013 6:54:11 PM via Website
Okay im doing simple stuff and i dont know why im getting errors can you guys please help me out.I get errors on this line "add = (Button) findviewById(R.id.Btnadd);"
Java code.
XML
Java code.
1package com.example.counter;
2
3import android.os.Bundle;
4import android.app.Activity;
5import android.view.Menu;
6import android.widget.*;
7
8public class Main extends Activity {
9
10 int counter = 0;
11 Button add,sub;
12 TextView Display;
13
14
15
16 @Override
17 protected void onCreate(Bundle savedInstanceState) {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.main);
20 }
21
22 add = (Button) findviewById(R.id.Btnadd);
23
24
25 @Override
26 public boolean onCreateOptionsMenu(Menu menu) {
27 // Inflate the menu; this adds items to the action bar if it is present.
28 getMenuInflater().inflate(R.menu.main, menu);
29 return true;
30 }
31
32}
2
3import android.os.Bundle;
4import android.app.Activity;
5import android.view.Menu;
6import android.widget.*;
7
8public class Main extends Activity {
9
10 int counter = 0;
11 Button add,sub;
12 TextView Display;
13
14
15
16 @Override
17 protected void onCreate(Bundle savedInstanceState) {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.main);
20 }
21
22 add = (Button) findviewById(R.id.Btnadd);
23
24
25 @Override
26 public boolean onCreateOptionsMenu(Menu menu) {
27 // Inflate the menu; this adds items to the action bar if it is present.
28 getMenuInflater().inflate(R.menu.main, menu);
29 return true;
30 }
31
32}
XML
1<LinearLayout xmlns:android=""
2 xmlns:tools=""
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6
7 >
8
9 <TextView
10 android:id="@+id/Tv1"
11 android:layout_width="wrap_content"
12 android:layout_height="wrap_content"
13 android:textSize="45sp"
14 android:layout_gravity="center"
15 android:text="@string/TvDisplay"
16 android:textColor="#5DA2FC" />
17
18 <Button
19
20 android:id="@+id/Btnadd"
21 android:layout_width="250dp"
22 android:layout_height="wrap_content"
23 android:layout_gravity="center_horizontal"
24 android:text="@string/Btn1"
25 />
26
27
28 <Button
29
30 android:id="@+id/Btnsub"
31 android:layout_width="250dp"
32 android:layout_height="wrap_content"
33 android:layout_gravity="center_horizontal"
34 android:text="@string/Btn2"
35 />
36
37
38
39
40
41</LinearLayout>
2 xmlns:tools=""
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6
7 >
8
9 <TextView
10 android:id="@+id/Tv1"
11 android:layout_width="wrap_content"
12 android:layout_height="wrap_content"
13 android:textSize="45sp"
14 android:layout_gravity="center"
15 android:text="@string/TvDisplay"
16 android:textColor="#5DA2FC" />
17
18 <Button
19
20 android:id="@+id/Btnadd"
21 android:layout_width="250dp"
22 android:layout_height="wrap_content"
23 android:layout_gravity="center_horizontal"
24 android:text="@string/Btn1"
25 />
26
27
28 <Button
29
30 android:id="@+id/Btnsub"
31 android:layout_width="250dp"
32 android:layout_height="wrap_content"
33 android:layout_gravity="center_horizontal"
34 android:text="@string/Btn2"
35 />
36
37
38
39
40
41</LinearLayout>
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.