Hey guys whatsup . I´m new here and i want to ask if you could help me with this error message ...
Yeah you know i´m already sit over 2 days on this error message cause i can`t find any problem in my Code you know ...
Here are my Files , what I´m doing wrong ? :
Thats not my whole code but here is a picture too from the debug tool :
I uploaded it .
and here is the file where I have my Button ... :
Here is the file that should open when I click the Button :
Thank you for everyone who help me ....
Code:
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.myapplication2.MainActivity.onCreate(MainActivity.java:47)
Yeah you know i´m already sit over 2 days on this error message cause i can`t find any problem in my Code you know ...
Here are my Files , what I´m doing wrong ? :
Java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openanmeldung();
}
});
BottomNavigationView navigation = findViewById(R.id.bottomnav);
navigation.setOnNavigationItemSelectedListener(this);
getSupportFragmentManager().beginTransaction().replace(fragment_container, new Home_Screen()).commit();
}
private void openanmeldung(){
Intent intent = new Intent(MainActivity.this,AnmeldungButton.class);
startActivity(intent);
}
Thats not my whole code but here is a picture too from the debug tool :
I uploaded it .
and here is the file where I have my Button ... :
Code:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="80dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<Button
android:text="Mehr infos"
android:layout_width="120dp"
android:layout_height="35dp"
android:id="@+id/button1"
android:layout_weight="1"
android:layout_marginTop="130dp"
android:layout_marginRight="170dp"
/>
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/maincolor"
>
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="HPI - 29.06.19"
android:textSize="24dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Juni22, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp"
/>
</android.support.v7.widget.CardView>
Here is the file that should open when I click the Button :
Code:
package com.example.myapplication2;
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 AnmeldungButton extends Fragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.moreinffos, container, false);
}
}
Thank you for everyone who help me ....