meine Taste mit dem ID-Radio, um zweite Aktivität zu starten, funktioniert nicht und meine App stürzt ab. Die zweite Schaltfläche startet jedoch eine andere Aktivität, die für den Moment leer ist. Kann mir bitte jemand sagen, was ich vermisst habe, damit meine App aufhört zu stürzen, wenn ich den Knopf drücke.Button wird nicht eine andere Aktivität starten
meine erste Tätigkeit xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mitja.radiohead.PrvaStran">
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayou xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mitja.radiohead.PrvaStran">
<LinearLayout
android:layout_width="368dp"
android:layout_height="0dp"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="49dp"
android:weightSum="1">
<ImageView
android:id="@+id/slika"
android:layout_width="match_parent"
android:layout_height="218dp"
android:layout_weight="0.16"
android:src="@drawable/radio"
android:layout_marginLeft="1dp"
android:layout_marginRight="2dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="@+id/radio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="0.50"
android:text="radio"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="323dp" />
<Button
android:id="@+id/predvajalnik"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="predvajalnik"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="371dp" />
</LinearLayout>
Java-Code der ersten Aktivität
public class PrvaStran extends AppCompatActivity {
private static Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prva_stran);
onClickButton();
onClickButton2();
}
public void onClickButton()
{
btn1 = (Button) findViewById(R.id.radio);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent openMainAct = new Intent(PrvaStran.this, Radio.class);
startActivity(openMainAct);
}
});
}
public void onClickButton2()
{
btn1 = (Button) findViewById(R.id.predvajalnik);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.example.mitja.radiohead.Predvajalnik");
startActivity(intent);
}
});
}
}
und der Android manifestxml Code. hier
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mitja.radiohead">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PrvaStran">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Radio"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.example.mitja.radiohead.Radio" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Predvajalnik">
<intent-filter>
<action android:name="com.example.mitja.radiohead.Predvajalnik" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Was bin ich dabei? Die zweite Aktivität wurde von einem Tutorial erstellt, das ich auf Youtube gesehen habe, um eine Listenansicht mit Bildern und Texten zu erstellen. Ich habe den Code von dieser Seite jetzt im Versuch, es in dieser App für die Praxis zu verwenden. Ich habe noch keine Erfahrung mit Android-Studio hatte, bevor ich so um eine kleine Anleitung bitten.
vergessen haben, eine Verbindung mit dem Code zu schreiben i auf für die zweite Aktivität verwenden welche die Taste zum öffnen hat https://stackoverflow.com/questions/42771902/a-am-trying-to-implement-a-custom-listview-using-arrayadapter-but-all-the-items –
Konnte Sie posten Absturzprotokoll? –
Bitte bearbeiten Sie Ihren Fragentitel. Weil Android Studio nichts mit deinem Problem zu tun hat. Android Studio ist ein _IDE_ und Android ist ein _Platform_ – Shashanth