Anfänger String types not allowed (at 'textColor' with value 'black'

Hag2bard

Bekanntes Mitglied
Hallo,

Ich habe mir ein paar Java Grundlagen angeeignet und möchte nun eine kleine simple Android App erstellen.
Dafür nutze ich Java N-IDE auf meinem Smartphone.
Das Testprogramm welches erstellt wird, gibt ein Hello World in der Mitte des Bildschirms aus.
Um zu verstehen wie Android Apps funktionieren habe ich aus dem Internet ein Beispiel kopiert, welches mir die Syntax für die Textformatierung anzeigt.

Wenn ich dieses in meine XML kopiere, bekomme ich die im Threadtitel genannte Fehlermeldung.

[CODE lang="xml" title="activity_main.xml aus dem Internet"]<?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:eek:rientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:eek:rientation="vertical">

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#008080"
android:textColor="black"
android:textSize="20sp"
android:gravity="left"
android:text="left" />

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#08f9bd"
android:textColor="black"
android:textSize="20sp"
android:gravity="center_horizontal"
android:text="center_horizontal" />

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#f418d2"
android:textColor="black"
android:textSize="20sp"
android:gravity="right"
android:text="right" />

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#aacaff"
android:textColor="black"
android:textSize="20sp"
android:gravity="center"
android:text="center" />

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#c443bf"
android:textColor="black"
android:textSize="20sp"
android:gravity="end"
android:text="end" />

</LinearLayout>
</LinearLayout>[/CODE]


[CODE lang="xml" title="activity_main.xml original"]<?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:eek:rientation="vertical">

<TextView
android:id="@+id/txt_hello"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hallo Welt" />

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#aacaff"
android:textSize="20sp"
android:gravity="center"
android:text="center" />


</LinearLayout>[/CODE]

[CODE lang="java" title="MainActivity.java"]package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;

import com.example.myapplication.R;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

}
[/CODE]
 
K

kneitzel

Gast
Vermutlich will er da keinen String wie "black" sondern einen Farbcode. Also ersetze black mal durch #000000
 

Jw456

Top Contributor
Vermutlich will er da keinen String wie "black" sondern einen Farbcode. Also ersetze black mal durch #000000
Ja das geht auch

Die Strings sind ja Standard mäßig auch schon vorhanden. Er wird schon das benutzen wollen. Er wird es wohl nur aus einem Beispiel aus dem Netz falsch oder zur hälfte abgeschrieben haben.
 

Hag2bard

Bekanntes Mitglied
Also mit einem Farbcode funktioniert es.

Wie kann man denn mehr anstatt eines starren Textes anzeigen?
Also sowas wie eine Konsole daraus machen.
Oder anders gefragt kann ich einen String anzeigen lassen?
 
Zuletzt bearbeitet:

Jw456

Top Contributor
Dazu musst du dir erst mal im code die Instanz der View holen.
Dann kannst du denn einen neuen Text setzten.

Java:
TextView textView = findViewById(R.id.txt_hello);
        textView.setText("neuer Text");


Ps hier ein link für den anfang
 
Zuletzt bearbeitet:

Jw456

Top Contributor
PS in deinem Layout hast du keine ID vergeben ohne geht das nicht wenn du im code auf die texte zugreifen willst.
 

Hag2bard

Bekanntes Mitglied
Ich glaube ich komme mit meiner Java N-ide nicht sehr weit.
Im Tutorial wird erklärt wie ich die MainActivity zu bauen habe.
Aber beim import von androidx.appcompat.app.AppCompatActivity meckert er rum.
The import cannot be resolved.
 

Hag2bard

Bekanntes Mitglied
Ich habe mir nochmal Gedanken gemacht.
Die AppCompatActivity gibt es bei meiner ide nicht, sie hat aber wahrscheinlich die selbe Funktion wie die Activity Klasse.
Ich habe meinen Code dementsprechend etwas umgebaut
Java:
package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        TextView welcomeMessageTV = new TextView(this);
        welcomeMessageTV.setText("Hello CodeYourApp World!");
        setContentView(welcomeMessageTV);
    }
}

Beim Compilieren meckert er allerdings bezugnehmend auf die style.xml

Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCombat.Light.DarkActionBar'.

Meine styles.xml sieht so aus
[CODE lang="xml" title="style.xml" highlight="3"]<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>[/CODE]

Wie änder ich die Zeile 3 am besten ab?
 

mihe7

Top Contributor
Die AppCompatActivity gibt es bei meiner ide nicht
Dann fehlt Dir die Lib. Früher war das die Support Library, heute ist das in AndroidX enthalten. Schau mal im Refactor-Menü, ggf. hast Du da einen Eintrag "Refactor to AndroidX", wenn nicht, oder falls das nicht funktioniert, deklariere einfach mal die Abhängigkeit androidx.appcompat:appcompat:1.3.1 in Deinem Gradle-File (s. https://developer.android.com/jetpack/androidx/releases/appcompat)

In der Support Library war der Import z. B. android.support.v7.app.AppCompatActivity, für AndroidX musst Du dagegen androidx.appcompat.app.AppCompatActivity importieren. Das dürfte die IDE aber automatisch machen, wenn Du diesbezüglich nix rumgestellt hast und die Abhängigkeit zur Lib deklariert wurde. Ja, das Android-Zeug ist alles etwas unübersichtlich :)
 

Jw456

Top Contributor
Welche App hast du die kostenlose oder die Pro Version?

Ich habe mir mal die kostenlose angesehen da ist glaube nur ein Projekt möglich und es wird nur die hälfte erstellt was Android Studio für ein Projekt erstellt.

Vielleicht müsstest du die Pro Version haben damit du es sinnvoll nutzen kannst.
Ich würde mir die Pro nicht kaufen weil ich Coden auf den Handy furcht bar finde.


Du müsstest dann auch ein Theme erstellen was dir Android Studio alles macht. Die App scheinbar nicht.
 

Jw456

Top Contributor
PS die App fragt dich am anfang auch nicht ob du ein Android Projekt estellen wilst sondern ein Java Projekt.

eine Frage nach einen Template kommt auch nicht wie im Studio.
vieleicht ist es inder Pro Version besser.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
O Android Anfänger: Quellcode nicht gefunden Android & Cross-Platform Mobile Apps 3
R Anfänger - Android relevante Themen ? Android & Cross-Platform Mobile Apps 2
S Anfänger Setup Fragen Android & Cross-Platform Mobile Apps 10
G GPS am Nokia Handy auslesen (Anfänger) Android & Cross-Platform Mobile Apps 15
R Adresseinträge / Anfänger Android & Cross-Platform Mobile Apps 3
J Empfehlungen für ME-Anfänger Android & Cross-Platform Mobile Apps 2
D NetBeans 4 und WTK [Anfänger] Android & Cross-Platform Mobile Apps 6
J Anfänger compilier Porbleme Android & Cross-Platform Mobile Apps 10
P anfänger Android & Cross-Platform Mobile Apps 7
W UTF-8 String Android & Cross-Platform Mobile Apps 66
W Base64 konvertierter URI String Android & Cross-Platform Mobile Apps 32
W String Array Pfad in Int setzen Android & Cross-Platform Mobile Apps 54
W Volley String Response gibt falchen if aus Android & Cross-Platform Mobile Apps 35
W Firestore String in Apps Laden Android & Cross-Platform Mobile Apps 10
T Android R.string.test+i Problem Android & Cross-Platform Mobile Apps 2
A Mit Java neues item in ein string-array einer Strings.xml schreiben Android & Cross-Platform Mobile Apps 4
C Zugriff auf die Position eines String- bzw Spinner-Arrays Android & Cross-Platform Mobile Apps 1
J Android String in andere Java-Dateien überführen Android & Cross-Platform Mobile Apps 1
J R.string.(variable) geht das Android & Cross-Platform Mobile Apps 3
R Android incomingNumber bein Eingehenden Anruf immer leerer String Android & Cross-Platform Mobile Apps 4
S SPLIT funktion bei STRING funktioniert nicht! Android & Cross-Platform Mobile Apps 4
G String an einen php Script senden Android & Cross-Platform Mobile Apps 8
J Plötzlich "java.lang.String cannot be converted to JSONObject" Android & Cross-Platform Mobile Apps 9
T int to string ... Android & Cross-Platform Mobile Apps 8
A String[] für Lisadapter Android & Cross-Platform Mobile Apps 4
M jsonobject cannot be cast to java.lang.string Android & Cross-Platform Mobile Apps 4
N Android Hilfe string to float geht nicht... Android & Cross-Platform Mobile Apps 4
J Einen String bewegen wie? Android & Cross-Platform Mobile Apps 3
R String wie WAV Datei nutzen Android & Cross-Platform Mobile Apps 4
C 2 kleine Probleme (Datei lesen, String durchsuchen) Android & Cross-Platform Mobile Apps 16
L String dem Display anpassen Android & Cross-Platform Mobile Apps 12
G Text parsen String to Double Android & Cross-Platform Mobile Apps 2
S ein String nach vorgegebenen Zeichen teilen Android & Cross-Platform Mobile Apps 3
N Zeichen im String löschen? Android & Cross-Platform Mobile Apps 18
M MIDlet + Datum in String Android & Cross-Platform Mobile Apps 5

Ähnliche Java Themen

Neue Themen


Oben