Neondottems
New Member
I made a perfectly working calculator program for practice for android. I didn't like the relative layout I started with and decided to try out grid layout. Now my \[code\]MainActivity.java\[/code\]doesn't see the \[code\]activity_main.xml\[/code\] file. I've checked the \[code\]R.java\[/code\] file and see a listing for \[code\]activity_main.xml\[/code\], with all the buttons listed. The \[code\]activity_main.xml\[/code\] parses just fine. I've tried rebuilding the program to no avail. Any ideas would be helpful! Here's the \[code\]activity_main.xml file\[/code\]\[code\]<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:alignmentMode="alignBounds" android:columnCount="8" android:columnOrderPreserved="false" android:useDefaultMargins="true" > <EditText android:id="@+id/total" android:layout_column="0" android:layout_columnSpan="6" android:layout_gravity="left" android:layout_row="0" android:clickable="false" android:ems="10" android:inputType="none|number" android:textAlignment="textEnd" android:width="500dp" > <requestFocus /> </EditText> <Button android:id="@+id/Button8" android:layout_column="1" android:layout_row="1" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="8" /> <Button android:id="@+id/Button9" android:layout_column="2" android:layout_row="1" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="9" /> <Button android:id="@+id/Button4" android:layout_column="0" android:layout_row="2" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="4" /> <Button android:id="@+id/Button5" android:layout_column="1" android:layout_row="2" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="5" /> <Button android:id="@+id/Button6" android:layout_column="2" android:layout_row="2" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="6" /> <Button android:id="@+id/ButtonMultiply" android:layout_column="3" android:layout_row="2" android:background="@drawable/custom_button" android:minHeight="40dip" android:minWidth="40dip" androidnClick="Multiply" android:text="*" android:textColor="@color/light_grey" /> <Button android:id="@+id/Button1" android:layout_column="0" android:layout_row="3" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="1" /> <Button android:id="@+id/Button2" android:layout_column="1" android:layout_row="3" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="2" /> <Button android:id="@+id/Button3" android:layout_column="2" android:layout_row="3" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="3" /> <Button android:id="@+id/ButtonMinus" android:layout_column="3" android:layout_row="3" android:background="@drawable/custom_button" android:minHeight="40dip" android:minWidth="40dip" androidnClick="Subtract" android:text="-" android:textColor="@color/light_grey" /> <Button android:id="@+id/ButtonDivide" android:layout_column="3" android:layout_gravity="right" android:layout_row="1" android:layout_rowSpan="2" android:background="@drawable/custom_button" android:minHeight="40dip" android:minWidth="40dip" androidnClick="Divide" android:text="/" android:textColor="@color/light_grey" /> <Button android:id="@+id/button0" android:layout_column="0" android:layout_columnSpan="2" android:layout_row="4" android:background="@drawable/button_light_grey" android:minHeight="20dp" android:minWidth="82dp" androidnClick="numberButtonEventHandler" android:text="0" /> <Button android:id="@+id/buttonPoint" android:layout_column="2" android:layout_row="4" android:background="@drawable/button_light_grey" android:minHeight="20dip" android:minWidth="40dp" androidnClick="numberButtonEventHandler" android:text="." android:width="20dip" /> <Button android:id="@+id/ButtonPlus" android:layout_column="3" android:layout_row="4" android:background="@drawable/custom_button" android:minHeight="40dip" android:minWidth="40dip" androidnClick="Add" android:text="+" android:textColor="@color/light_grey" /> <Button android:id="@+id/ButtonEqueals" android:layout_column="4" android:layout_row="3" android:layout_rowSpan="2" android:background="@drawable/custom_button" android:height="40dp" android:minHeight="82dp" android:minWidth="20dp" androidnClick="Equeals" android:text="=" android:textColor="@color/light_grey" android:width="40dp" /> <Button android:id="@+id/Button7" android:layout_column="0" android:layout_row="1" android:background="@drawable/button_light_grey" android:minHeight="40dip" android:minWidth="40dip" androidnClick="numberButtonEventHandler" android:text="7" /></android.support.v4.widget.GridLayout>\[/code\]And here's the \[code\]MainActivity.java\[/code\] file\[code\]package com.example.calculator;import android.R;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.TextView;public class MainActivity extends Activity{ private String textTotal = ""; Total total = new Total(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); <---here I get my first error eclipse help suggests changing //setButtonListeners(); to activity_list_item. This } doesn't help @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void numberButtonEventHandler(View v) { textTotal += ((Button) v).getText(); TextView total = (TextView)findViewById(R.id.total); total.setText(textTotal); } public void Add(View v){ try { total.doMath(Double.parseDouble(textTotal)); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } total.setOperater("+"); TextView TextViewtotal = (TextView)findViewById(R.id.total); TextViewtotal.setText(Double.toString(total.getTotalValue())); textTotal = ""; } public void Subtract(View v){ try { total.doMath(Double.parseDouble(textTotal)); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } total.setOperater("-"); TextView TextViewtotal = (TextView)findViewById(R.id.total); TextViewtotal.setText(Double.toString(total.getTotalValue())); textTotal = ""; } public void Multiply(View v){ try { total.doMath(Double.parseDouble(textTotal)); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } total.setOperater("*"); TextView TextViewtotal = (TextView)findViewById(R.id.total); TextViewtotal.setText(Double.toString(total.getTotalValue())); textTotal = ""; } public void Divide(View v){ try { total.doMath(Double.parseDouble(textTotal)); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } total.setOperater("/"); TextView TextViewtotal = (TextView)findViewById(R.id.total); TextViewtotal.setText(Double.toString(total.getTotalValue())); textTotal = ""; } public void Equeals(View v){ try { total.doMath(Double.parseDouble(textTotal)); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } total.setOperater(""); TextView TextViewtotal = (TextView)findViewById(R.id.total); TextViewtotal.setText(Double.toString(total.getTotalValue())); textTotal = ""; }}\[/code\]Console output now:\[code\][2013-04-03 22:19:26 - Calculator] Could not find Calculator.apk![2013-04-03 22:19:53 - Calculator] ------------------------------[2013-04-03 22:19:53 - Calculator] Android Launch![2013-04-03 22:19:53 - Calculator] adb is running normally.[2013-04-03 22:19:53 - Calculator] Could not find Calculator.apk![2013-04-03 22:20:58 - Calculator] ------------------------------[2013-04-03 22:20:58 - Calculator] Android Launch![2013-04-03 22:20:58 - Calculator] adb is running normally.[2013-04-03 22:20:58 - Calculator] Could not find Calculator.apk![2013-04-03 22:24:29 - Calculator] ------------------------------[2013-04-03 22:24:29 - Calculator] Android Launch![2013-04-03 22:24:29 - Calculator] adb is running normally.[2013-04-03 22:24:29 - Calculator] Could not find Calculator.apk!\[/code\]next logcat output:\[code\]04-03 22:46:16.121: E/AndroidRuntime(17973): FATAL EXCEPTION: main04-03 22:46:16.121: E/AndroidRuntime(17973): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator/com.example.calculator.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.GridLayout04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.ActivityThread.access$2300(ActivityThread.java:125)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.os.Handler.dispatchMessage(Handler.java:99)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.os.Looper.loop(Looper.java:123)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.ActivityThread.main(ActivityThread.java:4627)04-03 22:46:16.121: E/AndroidRuntime(17973): at java.lang.reflect.Method.invokeNative(Native Method)04-03 22:46:16.121: E/AndroidRuntime(17973): at java.lang.reflect.Method.invoke(Method.java:521)04-03 22:46:16.121: E/AndroidRuntime(17973): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)04-03 22:46:16.121: E/AndroidRuntime(17973): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)04-03 22:46:16.121: E/AndroidRuntime(17973): at dalvik.system.NativeStart.main(Native Method)04-03 22:46:16.121: E/AndroidRuntime(17973): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.GridLayout04-03 22:46:16.121: E/AndroidRuntime(17973): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)04-03 22:46:16.121: E/AndroidRuntime(17973): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:200)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.Activity.setContentView(Activity.java:1647)04-03 22:46:16.121: E/AndroidRuntime(17973): at com.example.calculator.MainActivity.onCreate(MainActivity.java:17)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)04-03 22:46:16.121: E/AndroidRuntime(17973): ... 11 more04-03 22:46:16.121: E/AndroidRuntime(17973): Caused by: java.lang.ClassNotFoundException: android.support.v4.widget.GridLayout in loader dalvik.system.PathClassLoader[/data/app/com.example.calculator-1.apk]04-03 22:46:16.121: E/AndroidRuntime(17973): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)04-03 22:46:16.121: E/AndroidRuntime(17973): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)04-03 22:46:16.121: E/AndroidRuntime(17973): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.view.LayoutInflater.createView(LayoutInflater.java:466)04-03 22:46:16.121: E/AndroidRuntime(17973): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)04-03 22:46:16.121: E/AndroidRuntime(17973): ... 19 more\[/code\]