How can I change or add more code to make this app to stop crashing? This activity is called "WhatBin", I simply wanted to make a button listen to when a person would click and change a text view. (VIEW PICTURES BELOW FOR MORE DETAILS.)
PICTURES: http://imgur.com/a/ODvHb
package com.example.tiffany.whatbin;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
public class WhatBin extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_what_bin);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final TextView txt_answer = (TextView) findViewById(R.id.txt_answer);
Button btn_go = (Button) findViewById(R.id.btn_go);
btn_go.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txt_answer.setText("Marker - Recycle Bin");
}
});
};
}
HERE IS THE XML FILE:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_padddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_what_bin" tools:context=".WhatBin">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:id="#+id/btn.go"
android:layout_marginBottom="113dp"
android:textColor="#drawable/abc_dialog_material_background_dark"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textEdit"
android:layout_alignBottom="#+id/btn.go"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/btn.go"
android:layout_toStartOf="#+id/btn.go" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/instructiontext"
android:id="#+id/textinstruc"
android:layout_below="#+id/textEdit"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/btn.go"
android:layout_toStartOf="#+id/btn.go" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/txt.1"
android:id="#+id/txt.answer"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
UPDATE
You are currently using abc_dialog_material_background_dark as textcolor. As you can see in the source of this resource, it is basically a shape. And, shape cannot be used for textcolor.
In your XML file at line 17 you have used a color. That color is of wrong type. My guess, you have used a drawable instead of a color.
Post your activity_what_bin.xml for further explanation.
Related
I have lots of layouts and activites and fragments. There are tabs in one activity called Hastane1 and it has four tabs in it. They don't have any problem but one of them has. I wanted to send a data from one Activity to a Fragment. They are seperate. Fragment is in Hastane1 activity but Haberlesme1 activity is in another place. It supposed to send the numbers which i entered in the activity called Haberlesme1 to the textView in the fragment called Hastane1Tab3Frag which is a tab of Hastane1.
The Android Studio itself doesn't have any errors but when i run the app on my phone, it stops when i pressed the button called "Gönder" (#id/button8).
Haberlesme1 (Activity):
package com.example.projev021.İllerPackage.KocaeliPackage.GebzePackage.GebzeFragments.Hastane1Fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.projev021.HaberlesmePackage.Haberlesme1;
import com.example.projev021.R;
public class Hastane1Tab3Frag extends Fragment {
Button goster;
TextView sonucText;
int sayi=0;
Haberlesme1.Ogrenci ogr;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.hastane1_tab3,container,false);
goster=(Button)v.findViewById(R.id.button13);
sonucText = (TextView)v.findViewById(R.id.textView3);
goster.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sonucText.setText(sayi);
}
});
return v;
}
public void sendData(int birinciSayi) {
this.sayi=birinciSayi;
}
public void sendOgrenci(Haberlesme1.Ogrenci ogrenci) {
this.ogr=ogrenci;
}
}
haberlesme1.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/kackisivar"
android:textSize="50sp"/>
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:ems="10"
android:inputType="number"
android:text="" />
<Button
android:id="#+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:background="#drawable/buttonshape"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/gonder"
android:textColor="#FFC107"
android:textSize="30sp"
android:onClick="calistir"/>
</LinearLayout>
Hastane1Tab3Frag (Fragment):
package com.example.projev021.İllerPackage.KocaeliPackage.GebzePackage.GebzeFragments.Hastane1Fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.projev021.HaberlesmePackage.Haberlesme1;
import com.example.projev021.R;
public class Hastane1Tab3Frag extends Fragment {
Button goster;
TextView sonucText;
int sayi=0;
Haberlesme1.Ogrenci ogr;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.hastane1_tab3,container,false);
goster=(Button)v.findViewById(R.id.button13);
sonucText = (TextView)v.findViewById(R.id.textView3);
goster.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sonucText.setText(sayi);
}
});
return v;
}
public void sendData(int birinciSayi) {
this.sayi=birinciSayi;
}
public void sendOgrenci(Haberlesme1.Ogrenci ogrenci) {
this.ogr=ogrenci;
}
}
hastane1tab3.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container">
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/kisisayisi_"
android:textSize="50sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:fontFamily="#font/lineto_circular_black"
android:text=""
android:textSize="100sp"
android:textColor="#000000" />
<Button
android:id="#+id/button13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:background="#drawable/buttonshape"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/goster"
android:textColor="#FFC107"
android:textSize="30sp"/>
</LinearLayout>
</FrameLayout>
And the screenshots:
I'm attempting to create a note taker using Firebase and I'm falling at the first hurdle as I'm getting the error as per the title of this question.
My XML file is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.android.frapp.NoteTakerActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:id="#+id/appBarLayout2">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimaryDark"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark" />
</android.support.design.widget.AppBarLayout>
<include
android:id="#+id/noteTitleTxt"
layout="#layout/content_note_taker" />
<EditText
android:id="#+id/noteTitleTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/appBarLayout2"
android:ems="10"
android:hint="Enter Title"
android:inputType="text" />
<Spinner
android:id="#+id/spinnerNoteType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/noteTitleTxt"
android:layout_marginTop="13dp"
android:entries="#array/type" />
<Button
android:id="#+id/addNoteBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/spinnerNoteType"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="Add Note" />
</RelativeLayout>
The java class in question is:
package com.example.android.frapp;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class NoteTakerActivity extends AppCompatActivity {
EditText editNoteTitle; // It's this causing the issue
Button addButton;
Spinner spinnerType;
DatabaseReference databaseNotes;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_taker);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
databaseNotes = FirebaseDatabase.getInstance().getReference("notes");
editNoteTitle = (EditText) findViewById(R.id.noteTitleTxt);
addButton = (Button) findViewById(R.id.addNoteBtn);
spinnerType = (Spinner) findViewById(R.id.spinnerNoteType);
addButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
addNote();
}
});
}
private void addNote() {
String title = editNoteTitle.getText().toString().trim();
String type = spinnerType.getSelectedItem().toString();
if (!TextUtils.isEmpty(title)) {
String id = databaseNotes.push().getKey(); // id being created is unique every time
Notes notes = new Notes(id, title, type);
databaseNotes.child(id).setValue(notes); // to send data to database
Toast.makeText(this, "Title added", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "You must give the note a title", Toast.LENGTH_SHORT).show();
}
}
}
I've made sure I don't have any duplicate edit text names and got rid of any classes and xml files that are no longer needed just to be sure.
I've cleaned and rebuilt I don't know how many times but can't get past this issue. Does anyone have any other ideas I can use/try?
Thanks
Here you have it twice!
<include
android:id="#+id/noteTitleTxt" // <-----------------
layout="#layout/content_note_taker" />
<EditText
android:id="#+id/noteTitleTxt" // <-----------------
Just remove the one id in your include tag. While not shown in your post, I bet its top container is RelativeLayout.
So i have a main activity that commits the transaction of a fragment that inflates the activity with an image view just like a main cover, and with the button "Sign up" that takes you to the signUp activity. However, all of that does work like it shoulds, the transaction works and the inflater does too, but the problem comes when:
I am trying to call a fragment (signUpForm) from the activity (signUp). The root of the problem is that the fragment transaction to signUpForm is not working because the toast programmed on it is not showing, so it does not even get to the inflater.
signUp class:
package com.example.joshumberto.workcon;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
public class signUp extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
getSupportFragmentManager().beginTransaction()
.add(R.id.sign_up_container, new signUpForm(), "signUpForm").commit();
}
}
activity_sign_up.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/sign_up_container"
tools:context=".signUp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="look, i should have inflated companions"
/>
</LinearLayout>
signUpForm class (only pasting the oncreate method, other things aren't needed):
package com.example.joshumberto.workcon;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class signUpForm extends Fragment implements View.OnClickListener {
EditText correo;
EditText telefono;
Button continuar;
public signUpForm(){
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setHasOptionsMenu(true);
}
public View OnCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Toast.makeText(
getActivity(),
"i am supposued to be created!!",
Toast.LENGTH_LONG).show();
View v = inflater.inflate(R.layout.fragment_sign_up_form, container, false);
correo = (EditText) v.findViewById(R.id.txt_usuario_correo);
telefono = (EditText) v.findViewById(R.id.txt_usuario_telefono);
continuar = (Button) v.findViewById(R.id.btn_registro_continuar);
continuar.setOnClickListener(this);
return v;
}
fragment_sign_up_form.xml (just button,textview and edit texts to inflate activity)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/colorSignUpBackground"
tools:context=".signUp"
android:id="#+id/sign_up_form" >
<!--<include android:id="#+id/toolbar"
layout="#layout/toolbar" />-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registro"
android:fontFamily="sans-serif-smallcaps"
android:textSize="#dimen/titulo_txt"
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/margin_top_standar" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_usuario_correo"
android:layout_marginTop="#dimen/margin_top_login_btn"
android:hint="Correo"
android:gravity="center"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_usuario_contrasena"
android:layout_marginTop="#dimen/margin_top_login_btn"
android:hint="Contrasena"
android:gravity="center"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_usuario_telefono"
android:layout_marginTop="#dimen/margin_top_login_btn"
android:hint="Telefono"
android:gravity="center"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Continuar"
android:id="#+id/btn_registro_continuar"
android:layout_gravity="center_horizontal" />
<!--<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/miLista"
></ListView>-->
Ideas? Thanks.
You should try replace() method instead of add(). like this.
getSupportFragmentManager().beginTransaction().replace(R.id.sign_up_container, new signUpForm(), "signUpForm").commit();
Hi i'm new to android programming and i'm having this issue where i'm sure that my code should work but doesn't.
This is my MainActivity.java:
package com.example.evo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton imageButton2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.open);
imageButton2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SecondScreenActivity.class);
}
} );
}
}
This is my SeconScreenActirity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
public class SecondScreenActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.high_score);
}
}
This is my highscore.xml layout file
<?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:background="#drawable/yedi"
android:orientation="vertical" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="220dp"
android:text="high scores"
android:textColor="#FA5882" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="29dp"
android:text="Evrim"
android:textColor="#00FFFF" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="320dp"
android:layout_marginTop="-17dp"
android:text="1528"
android:textColor="#CC2EFA" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="20dp"
android:text="Selin"
android:textColor="#00FFFF" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="320dp"
android:layout_marginTop="-17dp"
android:text="1016"
android:textColor="#CC2EFA" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="11dp"
android:text="Muhammed"
android:textColor="#00FFFF" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="320dp"
android:layout_marginTop="-17dp"
android:text="800"
android:textColor="#CC2EFA" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="72dp"
android:layout_height="0dp"
android:layout_marginTop="80dp"
android:layout_weight="0.16"
android:src="#drawable/abc_ic_ab_back_holo_light"
android:contentDescription="#string/todo"/>
</LinearLayout>
This is my open.xml where i have my imageButton2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/son"
android:paddingBottom="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_horizontal_margin"
android:screenOrientation="landscape"
tools:context="com.example.kkk.MainActivity$PlaceholderFragment" >
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/highscore" android:contentDescription="#string/todo"/>
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_above="#+id/imageButton2"
android:layout_alignLeft="#+id/imageButton2"
android:src="#drawable/play" android:contentDescription="#string/todo"/>
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton3"
android:layout_centerHorizontal="true"
android:src="#drawable/exit" android:contentDescription="#string/todo"/>
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/imageButton2"
android:layout_below="#+id/imageButton2"
android:src="#drawable/aboutt" android:contentDescription="#string/todo"/>
</RelativeLayout>
I also updated my AndroidManifest.xml to add SeconScreenActivity.java
And i'm getting this
java.lang.RuntimeException: Unable to start activity
ComponentInfo java.lang.NullPointerException
errors please plase help!
You never initialize your imageButton element in your first activity.
So you get the NullPointerException when trying to assign to it the click listener.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.open);
//or whatever the id is for the image button in the open layout
imageButton2 = (ImageButton) findViewById(R.id.imageButton2);
imageButton2.setOnClickListener(new View.OnClickListener() {
You missed to take reference of ImageButton from open layout:
imageButton2 = (ImageButton) findViewById(R.id.<ImageButtonIdInOpenXml);
Just add below line
imageButton2 = (ImageButton)findViewById(R.id.imageButton1);
after
setContentView(R.layout.open);
Your are getting error because view ImageButton is not initialized
I added a new font called cgib.ttf, I went to MainActivity.java to add the 2 titleTexts
Here is the activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#1d72c3"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="#string/titleText"
android:textColor="#ffffff"
android:textSize="55sp" />
<TextView
android:id="#+id/kark"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="#string/titleText2"
android:textColor="#ffffff"
android:textSize="30sp" />
</LinearLayout>
Here is the MainActivity.java
package com.sa.damas;
import android.R;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initTypeFace();
}
private void initTypeFace() {
Typeface cgib = Typeface.createFromAsset(getAssets(), "fonts/cgib.ttf");
TextView titleText=(TextView) findViewById(R.id.title);
titleText.setTypeface(cgib);
TextView titleText2=(TextView) findViewById(R.id.kark);
titleText2.setTypeface(cgib);
}
}
The title is fixed and the second (kark) couldnt be found in the list
Replace import android.R; with import R;
android.R contains the system resources, not your project's resources