Android InflateException in unknown class when creating alert from XML file - android-studio

I have changed the app theme from Theme.appcompat to Theme.MaterialComponents
error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rohindh.kcthappytummy, PID: 16582
android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating
class <unknown>
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.createpopup(AddedtRecyclerAdapter.java:70)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.access$000(AddedtRecyclerAdapter.java:26)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter$1.onClick(AddedtRecyclerAdapter.java:62)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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:858)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme
to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at
com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at
com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:458)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:417)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
at android.view.LayoutInflater.createView(LayoutInflater.java:647) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.createpopup(AddedtRecyclerAdapter.java:70) 
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.access$000(AddedtRecyclerAdapter.java:26) 
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter$1.onClick(AddedtRecyclerAdapter.java:62) 
at android.view.View.performClick(View.java:6597) 
at android.view.View.performClickInternal(View.java:6574) 
at android.view.View.access$3100(View.java:778) 
at android.view.View$PerformClick.run(View.java:25885) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
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:858) 
When user clicks the edit button, an Alert dialog window should appear but I don't know what I'm missing
Adapter code
public class AddedtRecyclerAdapter extends RecyclerView.Adapter<AddedtRecyclerAdapter.ViewHolder> {
private Context context;
private ArrayList<Dishmodel> dishmodellist;
//pop elements and requirement
private AlertDialog.Builder build;
private AlertDialog dialog;
private EditText nameedt,desedt,pricedt;
private ImageButton closebtn;
private Button addbtn;
private ProgressBar progressBar;
public AddedtRecyclerAdapter(Context context, ArrayList<Dishmodel> dishmodellist) {
this.context = context;
this.dishmodellist = dishmodellist;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.dish_list_item,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
#Override
public void onBindViewHolder(#NonNull AddedtRecyclerAdapter.ViewHolder holder, final int position) {
final Dishmodel dish= dishmodellist.get(position);
holder.name.setText(dish.getName());
holder.price.setText(String.valueOf(dish.getPrice()));
holder.descirption.setText(dish.getDescription());
//edit btn clicked then create a pop window and send the current array with is position
holder.edtbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createpopup(dish,position);
}
});
}
private void createpopup(Dishmodel dish, int position) {
build = new AlertDialog.Builder(context);
View view = LayoutInflater.from(context).inflate(R.layout.popup,null);
nameedt = view.findViewById(R.id.itemname);
desedt = view.findViewById(R.id.itemdes);
pricedt = view.findViewById(R.id.itemprice);
addbtn = view.findViewById(R.id.itemaddbtn);
closebtn = view.findViewById(R.id.closebtn);
progressBar = view.findViewById(R.id.addprogress);
build.setView(view);
dialog = build.create();
dialog.show();
}
#Override
public int getItemCount() {
return dishmodellist.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name,descirption,price;
ImageButton edtbtn,deletebtn;
public ViewHolder(#NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.dishname);
descirption = itemView.findViewById(R.id.dishdes);
price = itemView.findViewById(R.id.dishprice);
edtbtn = itemView.findViewById(R.id.editbtn);
deletebtn = itemView.findViewById(R.id.deletebtn);}
}
error in 26 line in xml ie material.TextInputLayout
xml code
<?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="380dp" android:paddingHorizontal="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/closeicon"
android:id="#+id/closebtn"
android:layout_alignParentEnd="true"
android:backgroundTint="#color/appcolor"
/>
<ProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/addprogress"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/itemname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto"
android:maxLines="1"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField1"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:hint="Item Description"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/itemdes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:fontFamily="#font/roboto"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField2"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:hint="Item Price"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/itemprice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:fontFamily="#font/roboto"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:backgroundTint="#color/appcolor"
android:layout_marginTop="25dp"
android:id="#+id/itemaddbtn"
android:text="Add"/>
</LinearLayout>
Manifest code
<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">
Style
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowDisablePreview">false</item>
</style>
<style name="myDialog" parent="Theme.MaterialComponents.DayNight.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.firebase:firebase-auth:19.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'}
I have referred to many solutions in stackoverflow but can't able to solve this issue. If anyone knows solution for this issue please help out with this.
Thanks in advance

Related

Unit testing. java.lang.NullPointerException

everyone! I am writing unit tests for the mobile app. But I have an error that I don't know how to solve. The error has the following form:
java.lang.NullPointerException
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:841)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:630)
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:223)
at com.example.projectMP3.SplashScreenActivityTest.testLaunchOfNewActivity(SplashScreenActivityTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Program code "SplashScreenActivity.java":
public class SplashScreenActivity extends AppCompatActivity {
LinearLayout linearLayout;
/** Toolbar */
androidx.appcompat.widget.Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
toolbar = findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
linearLayout = findViewById(R.id.Splash_Activity);
linearLayout.setOnClickListener(v -> {
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
finish();
});
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
);
Objects.requireNonNull(getSupportActionBar()).hide();
Thread thread = new Thread() {
public void run() {
try {
sleep(3000);
} catch (Exception e) {
e.printStackTrace();
} finally {
Intent intent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(intent);
finish();
}
}
};
thread.start();
}
}
Program code "SplashScreenActivityTest.java":
import android.widget.TextView;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
public class SplashScreenActivityTest {
#Test
public void testLaunchOfNewActivity() {
SplashScreenActivity activity = new SplashScreenActivity();
TextView nameApplication = activity.findViewById(R.id.textView3);
assertNotNull(nameApplication.getText());
}
}
Program code "activity_splash_screen.xml":
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/Splash_Activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
tools:context=".SplashScreenActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#drawable/tab_indicater"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView2"
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/splash_screen_logo"
android:layout_marginTop="100dp"
app:tint="#120a8f"
android:contentDescription="#string/startSplashScreen" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="cursive"
android:gravity="center"
android:text="#string/appName"
android:textColor="#FFAB00"
android:textSize="50sp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:layout_marginTop="2dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/all_rights_are_reserved"
android:textColor="#color/white"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
This is my first time writing unit tests. I hope for your help! Thank you in advance.
The issue related to your Activity class. You just tried to test activity like a simple class. But in the android, Activity it's a system component managed by the system, and you can't just create an Activity using constructor.
On the official site it has a documentation how to test an activity:
https://developer.android.com/guide/components/activities/testing
It seems you are calling the activity and accessing the UI component in that activity. I don't know if you can do that in unit test without launching the app which makes it Instrumented test(which should be tested with AndroidJunit4)

popup window on my map Fragment android studio

can anyone help me with this i want to show a popupwindow on top of my map fragment when i click on a button it will display a popupwindow that contains text for example the text will be how the user will navigate the map
public class FirstFragment extends Fragment {
public FirstFragment() {
// require a empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_first, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.maps); //use SuppoprtMapFragment for using in fragment instead of activity MapFragment = activity SupportMapFragment = fragment
mapFragment.getMapAsync(new OnMapReadyCallback() {
public void onMapReady(#NonNull GoogleMap googleMap) {
GoogleMap mMap = googleMap;
mMap.getUiSettings().setMyLocationButtonEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setBuildingsEnabled(true);
mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(requireContext()));
mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(requireContext(), R.raw.style));
CameraPosition googlePlex = CameraPosition.builder()
.target(new LatLng(14.5768, 121.0332))
.zoom(15)
.bearing(0)
.tilt(60)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(googlePlex), 4000, null);
mMap.addMarker(new MarkerOptions()
.icon(bitmapDescriptorFromVector(getActivity(), R.drawable.ic_baseline_location_city_24))
.position(new LatLng(14.5768, 121.0332))
.title("Mandaluyong");
KmlLayer layer = null;
try {
layer = new KmlLayer(mMap, R.raw.mandaluyong, getContext());
} catch (Exception e) {
e.printStackTrace();
}
for (KmlPlacemark placemark : layer.getPlacemarks()) {
}
layer.addLayerToMap();
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng point) {
mMap.addMarker(new MarkerOptions()
.position(point)
.title("Home")
.snippet("Your PlaceMarker!!!"));
this is the xml file i've added a floating action button on it now when click it i want to display a popup window that will show on top of my map fragment ive tried different things and it crashes or doesnt show the popup ive decided to ask here because i am stuck in this part
}
<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"
tools:context=".MainActivity"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment
android:id="#+id/maps"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/infobutton"
android:src="#drawable/ic_baseline_info_24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="97dp"
android:clickable="true"
android:rotation="0" />
<FrameLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="60dp"
android:layout_marginTop="300dp">
</FrameLayout>
</RelativeLayout>
here are the java and xml files of the map fragment that i used
[maps app pic][1]
[1]: https://i.stack.imgur.com/xaBIR.png

Why does Unexpected implicit cast to `EditText`: layout tag was `TextView`

I have a problem, I'm trying to finish the lesson Android fundamentals 02.3: Implicit intents, but there are some errors
the first one is Unexpected implicit cast to EditText: layout tag was TextView
the second one is Consider adding a declaration to your manifest when calling this \ method; see https://g.co/dev/packagevisibility for details
when running the application, it automatically stops immediately, I have tried it on the emulator and on real devices
source codelab : https://developer.android.com/codelabs/android-training-activity-with-implicit-intent?index=..%2F..%2Fandroid-training#0
Code MainActivity.java
package com.example.implicitintents;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.ShareCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText mWebsiteEditText;
private EditText mLocationEditText;
private EditText mShareTextEditText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebsiteEditText = findViewById(R.id.website_edittext);
mLocationEditText = findViewById(R.id.location_edittext);
mShareTextEditText = findViewById(R.id.share_edittext);
}
public void openWebsite(View view) {
String url = mWebsiteEditText.getText().toString();
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
public void openLocation(View view) {
String loc = mLocationEditText.getText().toString();
Uri addressUri = Uri.parse("geo:0,0?q=" + loc);
Intent intent = new Intent(Intent.ACTION_VIEW, addressUri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
public void shareText(View view) {
String txt = mShareTextEditText.getText().toString();
String mimeType = "text/plain";
ShareCompat.IntentBuilder
.from(this)
.setType(mimeType)
.setChooserTitle("Share this text with: ")
.setText(txt)
.startChooser();
}
}
Code Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:padding="16dp"
tools:context="MainActivity">
<TextView
android:id="#+id/website_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_uri" />
<Button
android:id="#+id/open_website_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openWebsite"
android:text="#string/button_uri" />
<TextView
android:id="#+id/location_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_loc" />
<Button
android:id="#+id/open_location_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openLocation"
android:text="#string/button_loc" />
<TextView
android:id="#+id/share_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_share" />
<Button
android:id="#+id/share_text_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="shareText"
android:text="#string/button_share" />
</LinearLayout>
In your xml file you declare three elements as Textview
<TextView
android:id="#+id/website_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_uri" />
<TextView
android:id="#+id/location_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_loc" />
<TextView
android:id="#+id/share_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_share" />
And then in your activity you declare your variables as EditText
private EditText mWebsiteEditText;
private EditText mLocationEditText;
private EditText mShareTextEditText;
And that's why your seeing those errors of casting.
Change in your xml file to EditText if you want to input some data or leave it like TextView if you want display some text but change the type of your variables in the activity. Make sure both are the same type

Android Studio: Click TextView to open an Specific Image on other Activity (Click Index Title to Open page on other Activity)

I m Developing Book Reading Project on Android studio, it has index activity with all titles and page numbers, when some one click on any title of index so on the an other activity the specific image should be open. all images are in Drawable folder.
here is XML Coding of First Activity coding Activity_main3.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1,2"
android:gravity="center"
android:shrinkColumns="1">
<TableRow
android:background="#000000"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/textview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:autoSizeTextType="uniform"
android:background="#FFFFFF"
android:gravity="center"
android:text="ناشر پاران...5"
android:textAppearance="?android:attr/textAppearanceLarge" />
/>
<TextView
android:id="#+id/textview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:autoSizeTextType="uniform"
android:background="#FFFFFF"
android:gravity="center"
android:text="پنهنجي پاران...6"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
The Second Activty coding is like this Activity_main.xml
<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="org.sindhila.www.sindhi_school_linguistics.MainActivity"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/SwitchImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:text="Next"
app:layout_constraintBaseline_toBaselineOf="#+id/SwitchImage2"
app:layout_constraintEnd_toStartOf="#+id/SwitchImage2"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#mipmap/pic3" />
<Button
android:id="#+id/SwitchImage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:text="Previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/SwitchImage" />
and Here is Coding Of mainactivity.java
it has two buttons for next and previous page and an image view to open images from drawable folder
package org.sindhila.www.sindhi_school_linguistics;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import java.util.Locale;
import uk.co.senab.photoview.PhotoViewAttacher;
public class MainActivity extends AppCompatActivity {
private static ImageView imageView;
private static Button SwitchImage;
private static Button SwitchImage2;
//
PhotoViewAttacher photoViewAttacher;
////
private int current_image_index;
int images[] = {R.mipmap.pic1, R.mipmap.pic2, R.mipmap.pic3,
R.mipmap.pic4,
R.mipmap.pic5,
R.mipmap.pic6,
R.mipmap.pic7,
R.mipmap.pic8,
R.mipmap.pic9,
R.mipmap.pic10,
R.mipmap.pic11,
R.mipmap.pic12,
R.mipmap.pic13,
R.mipmap.pic14,
R.mipmap.pic15,
R.mipmap.pic16,
R.mipmap.pic17,
R.mipmap.pic18,
R.mipmap.pic19,
R.mipmap.pic20,
R.mipmap.pic21,
R.mipmap.pic22,
R.mipmap.pic23,
R.mipmap.pic24,
R.mipmap.pic25,
R.mipmap.pic26,
R.mipmap.pic27,
R.mipmap.pic28,
R.mipmap.pic29,
R.mipmap.pic30,
R.mipmap.pic31,
R.mipmap.pic32,
R.mipmap.pic33,
R.mipmap.pic34,
R.mipmap.pic35,
R.mipmap.pic36,
R.mipmap.pic37,
R.mipmap.pic38,
R.mipmap.pic39,
R.mipmap.pic40,
R.mipmap.pic41,
R.mipmap.pic42,
R.mipmap.pic43,
R.mipmap.pic44,
R.mipmap.pic45,
R.mipmap.pic46,
R.mipmap.pic47,
R.mipmap.pic48,
R.mipmap.pic49,
R.mipmap.pic50,
R.mipmap.pic51,
R.mipmap.pic52,
R.mipmap.pic53,
R.mipmap.pic54,
R.mipmap.pic55,
R.mipmap.pic56,
R.mipmap.pic57,
R.mipmap.pic58,
R.mipmap.pic59,
R.mipmap.pic60,
R.mipmap.pic61,
R.mipmap.pic62,
R.mipmap.pic63,
R.mipmap.pic64,
R.mipmap.pic65,
R.mipmap.pic66,
R.mipmap.pic67,
R.mipmap.pic68,
R.mipmap.pic69,
R.mipmap.pic70,
R.mipmap.pic71,
R.mipmap.pic72,
R.mipmap.pic73,
R.mipmap.pic74,
R.mipmap.pic75,
R.mipmap.pic76,
R.mipmap.pic77,
R.mipmap.pic78,
R.mipmap.pic79,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonClick();
buttonClick2();
//////
imageView = (ImageView)findViewById(R.id.imageView);
Drawable drawable = getResources().getDrawable(R.mipmap.pic1);
imageView.setImageDrawable(drawable);
photoViewAttacher = new PhotoViewAttacher(imageView);
photoViewAttacher.update();
//////
}
public void buttonClick() {
imageView = (ImageView) findViewById(R.id.imageView);
SwitchImage = (Button) findViewById(R.id.SwitchImage);
SwitchImage.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
current_image_index++;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
}
}
);
}
public void buttonClick2() {
imageView = (ImageView) findViewById(R.id.imageView);
SwitchImage2 = (Button) findViewById(R.id.SwitchImage2);
SwitchImage2.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
if (current_image_index!=0) {
current_image_index--;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
}
}
}
);
}
}
Every thing is working Fine, i need to have hyperlink on Textview (on Activity_main3.xml and Main3Activity.java) to open specific image on Activity_main.xml/MainActivity.java
i have used following Coding but it produce error how to solve it please help. i want to click a textview on one activity and open specific image on other activity in imageview
in xml file of first activity in textview i added
android:onClick="onClick"
android:clickable="true"
.... added coding to first index activity named Main3activity.java where textviews are placed when I click textview it should open other activity and an image in it
public void onClick(View v) {
Intent intent = new Intent(Main3Activity.this,
MainActivity.class);
intent.putExtra("pic", pic4.png);
startActivity(intent);
} ...
and this coding to mainactivity.java where image should be opened in image view
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonClick();
buttonClick2();
setContentView(R.mipmap.pic1);
ImageView iv = (ImageView) findViewById(R.id.imageView);
iv.setImageResource(getIntent().getIntExtra("img", 0));

Application stops but there is no error

Here is the new logcat of the error, I do not understand what it is about I can't seem to figure out this error
11-25 15:56:18.773 6776-6776/com.example.ghost.prochat E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ghost.prochat/com.example.ghost.prochat.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2204)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5069)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.ghost.prochat.MainActivity.onCreate(MainActivity.java:56)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) 
at android.app.ActivityThread.access$600(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5069) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.ghost.prochat.MainActivity.onCreate(MainActivity.java:56) 
at android.app.Activity.performCreate(Activity.java:5104) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) 
at android.app.ActivityThread.access$600(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5069) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
at android.view.View.(View.java:3340)
at android.view.ViewGroup.(ViewGroup.java:431)
at android.widget.LinearLayout.(LinearLayout.java:176)
at android.widget.LinearLayout.(LinearLayout.java:172)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.ghost.prochat.MainActivity.onCreate(MainActivity.java:56) 
at android.app.Activity.performCreate(Activity.java:5104) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) 
at android.app.ActivityThread.access$600(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5069) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 
my mainActivity is as follows
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
//defining view objects
private EditText editTextEmail;
private EditText displayUsername;
private EditText editTextPassword;
private Button buttonSignup;
private TextView textViewSignin;
private ProgressDialog progressDialog;
//defining firebaseauth object
private FirebaseAuth firebaseAuth;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initializing firebase auth object
firebaseAuth = FirebaseAuth.getInstance();
//if getCurrentUser does not returns null
if (firebaseAuth.getCurrentUser() != null) {
//that means user is already logged in
//so close this activity
finish();
//and open profile activity
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
//initializing views
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
displayUsername = (EditText) findViewById(R.id.displayUsername);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
textViewSignin = (TextView) findViewById(R.id.textViewSignin);
buttonSignup = (Button) findViewById(R.id.buttonSignup);
progressDialog = new ProgressDialog(this);
//attaching listener to button
buttonSignup.setOnClickListener(this);
textViewSignin.setOnClickListener(this);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
private void registerUser() {
//getting email and password from edit texts
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
//checking if email and passwords are empty
if (TextUtils.isEmpty(email)) {
Toast.makeText(this, "Please enter email", Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(this, "Please enter password", Toast.LENGTH_LONG).show();
return;
}
//if the email and password are not empty
//displaying a progress dialog
progressDialog.setMessage("Registering Please Wait...");
progressDialog.show();
//creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
//checking if success
if (task.isSuccessful()) {
finish();
final FirebaseUser user = task.getResult().getUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(String.valueOf(displayUsername))
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.png"))
.build();
user.updateProfile(profileUpdates);
FirebaseDatabase.getInstance().getReference("users").child(user.getUid()).setValue(UserList.user);
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
} else {
//display some message here
Toast.makeText(MainActivity.this, "Registration Error", Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
});
}
#Override
public void onClick(View view) {
if (view == buttonSignup) {
registerUser();
}
if (view == textViewSignin) {
//open login activity when user taps on the already registered textview
startActivity(new Intent(this, LoginActivity.class));
}
}
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Main Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
#Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
#Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
}
my main.activity is here, i cant see any errors
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/head"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.ghost.prochat.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="User Registration"
android:id="#+id/textView"
android:layout_gravity="center_horizontal" />
<EditText
android:id="#+id/displayUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Username"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter password"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Signup" />
<TextView
android:text="Already Registered? Signin Here"
android:id="#+id/textViewSignin"
android:textAlignment="center"
android:layout_margin="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Your crash is caused by the following:
Caused by: java.lang.UnsupportedOperationException: Can't convert to
dimension: type=0x1 at
android.content.res.TypedArray.getDimensionPixelSize
So the problem is in one of your dimensions:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
I can guess, that you used wrong dimension type, e.g. sp instead of dp
Here is how a right dimension should look:
<dimen name="activity_vertical_margin">36dp</dimen>
Also please ensure your dimension is defined in an xml in the valuesfolder as it mentioned in this answer

Resources