N
no1Ltan
Fortgeschrittenes Mitglied
- 7
Hallo allerseits,
wenn ich in einer komplexen App eine bestimmte Funktionalität nicht umsetzen/einbinden kann,
erstelle ich meist eine neue kleine App, um mich nur auf diesen 1 Punkt zu konzentrieren.
(Ist auch für die anderen dann einfacher und schneller lesbar, da kaum Code vorhanden ist.)
Jedenfalls habe ich in letzter Zeit immer wieder das Problem, dass selbst diese Mini-Test-Apps nicht starten.
Obwohl ich keinen Fehler in den Layouts oder den java-Codes sehe, hab ich keine Chance, die App zum Laufen zu bekommen.
Diese App besteht aus 1 Activity und 2 Fragmenten.
Ich habe sogar extra noch zusätzlich Codezeilen entfernt.
MainActivity.java
Fragment1.java:
Fragment2.java:
activity_main.xml
fragment1.xml
fragment2.xml
content_main.xml
strings.xml
styles.xml
AndroidManifest.xml
build.gradle
"Build completed successfully" heißt es.
Allerdings erscheint beim Starten der App immer die Meldung: "RefreshFragment has stopped."
Was kann ich als "normaler User" denn tun, um den Fehler ausfindig zu machen?
Kann der Debugger in diesem Fall helfen?
Oder ist das einfach nur ein weiterer typischer Anfängerfehler?
P.S. Wie gesagt, auch mit den Buttons und TextViews im Code tut sich nichts.
Danke für jede Hilfe!
wenn ich in einer komplexen App eine bestimmte Funktionalität nicht umsetzen/einbinden kann,
erstelle ich meist eine neue kleine App, um mich nur auf diesen 1 Punkt zu konzentrieren.
(Ist auch für die anderen dann einfacher und schneller lesbar, da kaum Code vorhanden ist.)
Jedenfalls habe ich in letzter Zeit immer wieder das Problem, dass selbst diese Mini-Test-Apps nicht starten.
Obwohl ich keinen Fehler in den Layouts oder den java-Codes sehe, hab ich keine Chance, die App zum Laufen zu bekommen.
Diese App besteht aus 1 Activity und 2 Fragmenten.
Ich habe sogar extra noch zusätzlich Codezeilen entfernt.
MainActivity.java
Code:
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity
{
ViewPager vp;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager vp = findViewById(R.id.vp);
SetUpViewPager(vp);
}
public void SetUpViewPager(ViewPager viewpage)
{
MyViewPagerAdapter Adapter = new MyViewPagerAdapter(getSupportFragmentManager());
Adapter.AddPageFragment(new Fragment1(), "Fragment1"); // Load pages inside of ViewPager
Adapter.AddPageFragment(new Fragment2(), "Fragment2");
viewpage.setAdapter(Adapter);
}
public class MyViewPagerAdapter extends FragmentPagerAdapter
{
private List<Fragment> MyFragment = new ArrayList<>();
private List<String> MyPageTitle = new ArrayList<>();
public MyViewPagerAdapter(FragmentManager manager)
{
super(manager);
}
public void AddPageFragment(Fragment Frag, String Title)
{
MyFragment.add(Frag);
MyPageTitle.add(Title);
}
@Override
public Fragment getItem(int i)
{
return MyFragment.get(i);
}
@Nullable
@Override
public CharSequence getPageTitle(int position)
{
return MyPageTitle.get(position);
}
@Override
public int getCount()
{
return 2; // 2 pages total
}
}
}
Fragment1.java:
Code:
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment1 extends Fragment
{
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View fragmentOne = inflater.inflate(R.layout.fragment1, container, false); // Link view and layout
return fragmentOne;
}
}
Fragment2.java:
Code:
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View fragmentTwo = inflater.inflate(R.layout.fragment2, container, false); // Link view and layout
return fragmentTwo;
}
}
activity_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
fragment1.xml
Code:
<?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">
<Button
android:id="@+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:text="Write 1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:text="Write 2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_1" />
</android.support.constraint.ConstraintLayout>
fragment2.xml
Code:
<?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">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textSize="30sp"
android:text="TextView"
android:background="@color/colorPrimaryDark"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
content_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager 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:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main"/>
strings.xml
Code:
<resources>
<string name="app_name">RefreshFragment</string>
</resources>
styles.xml
Code:
<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>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.USER.refreshfragment">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle
Code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.USER.refreshfragment"
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
"Build completed successfully" heißt es.
Allerdings erscheint beim Starten der App immer die Meldung: "RefreshFragment has stopped."
Was kann ich als "normaler User" denn tun, um den Fehler ausfindig zu machen?
Kann der Debugger in diesem Fall helfen?
Oder ist das einfach nur ein weiterer typischer Anfängerfehler?
P.S. Wie gesagt, auch mit den Buttons und TextViews im Code tut sich nichts.
Danke für jede Hilfe!