MainActivity.java nicht erkennen activity_main.xml

Machte ich eine perfekt funktionierende Rechner-Programm für die Praxis entwickelt. Ich wusste nicht, wie die relative layout angefangen habe ich mit und beschloss zu versuchen, grid-layout. Nun meine MainActivity.java
nicht sehen, die activity_main.xml - Datei. Ich habe die R.java - Datei und sehen, eine Liste für activity_main.xml mit alle Tasten aufgeführt. Die activity_main.xml analysiert Prima. Ich habe versucht, Wiederaufbau des Programm-ohne Erfolg. Irgendwelche Ideen wäre hilfreich!!! Hier ist die activity_main.xml file

<?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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="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"
        android:onClick="numberButtonEventHandler"
        android:text="7" />



</android.support.v4.widget.GridLayout>

Und hier ist die MainActivity.java Datei

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 = "";
    }



}

Ausgabe in der Konsole jetzt:

[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!

nächsten logcat Ausgabe:

04-03 22:46:16.121: E/AndroidRuntime(17973): FATAL EXCEPTION: main
04-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.GridLayout
04-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.GridLayout
04-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 more
04-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
  • nach dem löschen von import-android.R der Fehler geht Weg, aber jetzt ist die Konsole beschwert sich, dass es nicht finden können Rechner.apk
  • Was bedeuten kann, nicht finden? Versuchen Sie, reinigen Sie und bauen-Projekt.
  • Check "bin" - Ordner in Ihrem Projekt, wenn es-Rechner Debuggen.apk oder somethink wie dieser name.
  • in bin ich habe AndroidManifest.xml, calculator.jar, R.txt
  • Ok. Im Projekt gibt es wichtige Dateien. Löschen von "bauen.Optionen" - Datei Zeile "android.Bibliothek=true". Dies ist für die Netbeans-IDE. Also versuchen Sie dies in eclipse und ich hoffe, dass dies helfen. In einer anderen Art und Weise versuchen zu finden Bibliothek "Projekt-Optionen" irgendwo in der eclipse-Projekt-Optionen, und deaktivieren Sie es.
  • scheint fix ein problem und erstellt eine andere... Aber ich denke, ich werde es verschieben auf eine andere Frage. Jetzt logcat beschwert sich ein schwerwiegender Fehler aufblasen android.Unterstützung.v4.- widget.gridlayout
  • Hier posten logcat-Ausgabe.
  • Caused by: java.lang.ClassNotFoundException: android.support.v4.widget.GridLayout in loader dalvik.system.PathClassLoader[/data/app/com.example.calculator-1.apk] Sind Sie sicher, dass Sie umgesetzt haben Android-Support-Library?(in android "lib" - Ordner)
  • ja, es ist da. es gibt auch eine Linie, die in den Projekteigenschaften android.Bibliothek.Referenz.1=../gridlayout_v7, sollte es nicht sagen gridlayou_v4?
  • nur eine Frage, passiert das jedes mal, wenn Sie versuchen, ändern Sie layouts in einer Ansicht?
  • android.library.reference.1=../gridlayout_v7, shouldn't it say gridlayou_v4? Weiß ich nicht. Ich immer nur Kopie Bibliothek ".jar" - Datei in den "lib" - Ordner in meinem Projekt Ordner. Sie können es versuchen, aber benutze es nie. Was passiert?
  • Ich habe versucht, ändern/löschen und Neuerstellen, die gleiche Sache, aber jetzt es sagt, dass es zu android.Unterstützung.v4.- widget.GridLayout. Vielleicht gibt es etwas falsch mit der jar-Datei
  • Hier hatten Sie das gleiche problem. Probieren Sie diese Lösung. stackoverflow.com/questions/9831019/...
  • ja, das hat auch nicht geholfen...
  • dzienki bardzo, ale musi isc spac teraz!!
  • Mütter taky půjdu. Mütter taky.

InformationsquelleAutor Craig Smith | 2013-04-03
Schreibe einen Kommentar