I am getting this ResourceNotFound Exception even though my code runs fine and exits onCreate.
public class MessageSelectionListActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>{
SimpleCursorAdapter mAdapter;
ListView mListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message_selection_list);
// Show the Up button in the action bar.
setupActionBar();
//My code
//Create a temporary loading bar while the Uri loads
ProgressBar progressBar = new ProgressBar(this);
progressBar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
progressBar.setIndeterminate(true);
mListView = (ListView)findViewById(R.id.smsListView);
mListView.setEmptyView(progressBar);
ViewGroup root = (ViewGroup)findViewById(android.R.id.content);
root.addView(progressBar);
//List item population mechanism
Cursor cursorSms = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
String[] fromColumns = {cursorSms.getColumnName(2), cursorSms.getColumnName(11)};
int[] toViews = {R.id.item_title, R.id.item_body};
this.mAdapter = new SimpleCursorAdapter(this, R.id.smsListView, cursorSms, fromColumns, toViews, 0);
this.mListView.setAdapter(this.mAdapter);
getSupportLoaderManager().initLoader(0, null, this);
}
/**
* Set up the {#link android.app.ActionBar}, if the API is available.
*/
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.message_selection_list, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(this, Uri.parse("content://sms/inbox/"), null, null, null, null );
}
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
}
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
}
}
The Logcat messages are as follows:
04-08 13:06:49.699: E/AndroidRuntime(2616): FATAL EXCEPTION: main
04-08 13:06:49.699: E/AndroidRuntime(2616): android.content.res.Resources$NotFoundException: Resource ID #0x7f090006 type #0x12 is not valid
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.content.res.Resources.getLayout(Resources.java:731)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.support.v4.widget.ResourceCursorAdapter.newView(ResourceCursorAdapter.java:106)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:252)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.AbsListView.obtainView(AbsListView.java:1536)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.ListView.makeAndAddView(ListView.java:1793)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.ListView.fillDown(ListView.java:718)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.ListView.fillFromTop(ListView.java:775)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.ListView.layoutChildren(ListView.java:1646)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.AbsListView.onLayout(AbsListView.java:1366)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.View.layout(View.java:7175)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.View.layout(View.java:7175)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.View.layout(View.java:7175)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.View.layout(View.java:7175)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.View.layout(View.java:7175)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.view.ViewRoot.handleMessage(ViewRoot.java:1866)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.os.Looper.loop(Looper.java:123)
04-08 13:06:49.699: E/AndroidRuntime(2616): at android.app.ActivityThread.main(ActivityThread.java:3687)
04-08 13:06:49.699: E/AndroidRuntime(2616): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 13:06:49.699: E/AndroidRuntime(2616): at java.lang.reflect.Method.invoke(Method.java:507)
04-08 13:06:49.699: E/AndroidRuntime(2616): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-08 13:06:49.699: E/AndroidRuntime(2616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-08 13:06:49.699: E/AndroidRuntime(2616): at dalvik.system.NativeStart.main(Native Method)
I am using code from a lot of different sources and stringing things together, so I know I am doing something wrong, but I cant seem to find it.
Thanks in advance.
UPDATE:
The Resource file for the Activity is as follows:
<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: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=".MessageSelectionListActivity" >
<TextView
android:id="#+id/smsPageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sms_page_title"
android:textSize="20sp" />
<TextView
android:id="#+id/smsPageInstructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/smsPageTitle"
android:layout_below="#+id/smsPageTitle"
android:text="#string/sms_page_instructions"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
<Button
android:id="#+id/makeExcelFileButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/smsPageInstructions"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/smsPageInstructions"
android:text="#string/make_excel_file" />
<ListView
android:id="#+id/smsListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/makeExcelFileButton"
android:layout_alignLeft="#+id/makeExcelFileButton"
android:layout_below="#+id/smsPageInstructions" />
And for the row layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<CheckBox
android:id="#+id/item_check_box"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/item_check_box"
android:singleLine="true" />
<TextView
android:id="#+id/item_body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/item_check_box"
android:layout_below="#id/item_title" />
</RelativeLayout>
So I was able to fix the problem.
here is how. The first message in the trace gave me the clue.
04-08 13:06:49.699: E/AndroidRuntime(2616): FATAL EXCEPTION: main 04-08 13:06:49.699: E/AndroidRuntime(2616): android.content.res.Resources$NotFoundException: Resource ID #0x7f090006 type #0x12 is not valid
The the resource with ID 0x7f090006 is invalid. so when I traced it back to the code, I had used the Resource ID instead of the resource name (R.layout.XXXXXX). changing it to that resolved the issue.
Related
I have two scripts
Activity:
public class HomeActivity extends AppCompatActivity {
public void Init()
{
//Do something
}
}
Fragment:
public class HomeFragment extends Fragment {
private FragmentHomeBinding binding;
#Override
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
HomeViewModel homeViewModel =
new ViewModelProvider(this).get(HomeViewModel.class);
binding = FragmentHomeBinding.inflate(inflater, container, false);
View root = binding.getRoot();
HomeActitvity homeActitvity = new HomeActivity()
homeActivity.Init()
return root;
}
}
When I run app I get this errors and app closes, but when I comment homeActivity.Init() app opens
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.limeinc.dabloonsbank/com.package.name.MainActivity}: java.lang.IllegalStateException
Binary XML file line #21 in com.package.name:layout/activity_main: Error inflating class fragment
this is activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<fragment //this is 21 line
android:id="#+id/nav_host_fragment_activity_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am using navigation bar template by android studio
I cant find solution in the internet, because they just dont work
so i wanted to creat a footer navigtion on the main activity and a fragment view above it
but now when i try to use the normal navigtion with the navigtion grafh it just crashes.
mainActivity java code:
package com.example.mywatchlist;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button homeBtn = findViewById(R.id.homeBtn);
Button profileBtn = findViewById(R.id.profileBtn);
Button socialBtn = findViewById(R.id.theSocialSearchBtn);
Button contentBtn = findViewById(R.id.contentContentSearchBtn);
homeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
homeFragment home = new homeFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainerView,home).commit();
}
});
profileBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
userProfileFragment profile = new userProfileFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainerView,profile).commit();
}
});
socialBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
socialSearchFragment social = new socialSearchFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainerView,social).commit();
}
});
contentBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
contentSearchFragment contentSearch = new contentSearchFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainerView,contentSearch).commit();
}
});
}
}
main activity.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="632dp"
app:defaultNavHost="true"
app:navGraph="#navigation/navigation" />
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/homeBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Go to\nHome"
android:textSize="12dp" />
<Button
android:id="#+id/profileBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="My\nProfile"
android:textSize="12dp" />
<Button
android:id="#+id/theSocialSearchBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Search for\nPeople"
android:textSize="12dp" />
<Button
android:id="#+id/contentContentSearchBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Search for\nContent"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
and now it crashes when i try to move in this fragment:
fragment to move from java code:
package com.example.mywatchlist;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
/**
* A simple {#link Fragment} subclass.
* Use the {#link contentSearchFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class contentSearchFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public contentSearchFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment contentSearchFragment.
*/
// TODO: Rename and change types and number of parameters
public static contentSearchFragment newInstance(String param1, String param2) {
contentSearchFragment fragment = new contentSearchFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_content_search,container, false);
// Inflate the layout for this fragment
Button searchBtn = view.findViewById(R.id.contentContentSearchBtn);
searchBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Navigation.findNavController(view).navigate(R.id.action_contentSearchFragment_to_contentFragment);
}
});
return view;
}
}
and this is the 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"
tools:context=".contentSearchFragment" >
<TextView
android:id="#+id/contentSearchTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C4FF80"
android:gravity="center"
android:text="Content search"
android:textSize="30dp" />
<Button
android:id="#+id/contentSearchAddNewContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add new content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFEB3B"
android:orientation="horizontal">
<EditText
android:id="#+id/contentSearchBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#C8C8C8"
android:ems="10"
android:hint="Search for content"
android:inputType="textPersonName"
android:minHeight="48dp" />
<Button
android:id="#+id/contentContentSearchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="502dp">
<TextView
android:id="#+id/contentSearchData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntesttest\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntesttest\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntesttest\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntesttest\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntesttest\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntesttest\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntesttest\ntest\ntest\ntest\ntest\ntest\XXXXXXXXXXXXXXXXXXntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\nXXXXXXXXXXXXXXXXX test\ntest\nXXXXXXXXXXXXXXXX\ntest\ntest\ntest\ntest\ntest" />
</ScrollView>
</LinearLayout>
and this is the navigtion xml:
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/navigation"
app:startDestination="#id/startFragment">
<fragment
android:id="#+id/startFragment"
android:name="com.example.mywatchlist.startFragment"
android:label="fragment_start"
tools:layout="#layout/fragment_start" >
<action
android:id="#+id/action_startFragment_to_logInFragment"
app:destination="#id/logInFragment" />
<action
android:id="#+id/action_startFragment_to_registerFragment"
app:destination="#id/registerFragment" />
</fragment>
<fragment
android:id="#+id/logInFragment"
android:name="com.example.mywatchlist.logInFragment"
android:label="fragment_log_in"
tools:layout="#layout/fragment_log_in" >
<action
android:id="#+id/action_logInFragment_to_homeFragment"
app:destination="#id/homeFragment" />
</fragment>
<fragment
android:id="#+id/registerFragment"
android:name="com.example.mywatchlist.registerFragment"
android:label="fragment_register"
tools:layout="#layout/fragment_register" >
<action
android:id="#+id/action_registerFragment_to_homeFragment"
app:destination="#id/homeFragment" />
</fragment>
<fragment
android:id="#+id/homeFragment"
android:name="com.example.mywatchlist.homeFragment"
android:label="fragment_home"
tools:layout="#layout/fragment_home" />
<fragment
android:id="#+id/userProfileFragment"
android:name="com.example.mywatchlist.userProfileFragment"
android:label="fragment_user_profile"
tools:layout="#layout/fragment_user_profile" />
<fragment
android:id="#+id/contentFragment"
android:name="com.example.mywatchlist.contentFragment"
android:label="fragment_content"
tools:layout="#layout/fragment_content" />
<fragment
android:id="#+id/contentSearchFragment"
android:name="com.example.mywatchlist.contentSearchFragment"
android:label="fragment_content_search"
tools:layout="#layout/fragment_content_search" >
<action
android:id="#+id/action_contentSearchFragment_to_contentFragment"
app:destination="#id/contentFragment" />
</fragment>
<fragment
android:id="#+id/socialSearchFragment"
android:name="com.example.mywatchlist.socialSearchFragment"
android:label="fragment_social_search"
tools:layout="#layout/fragment_social_search" >
<action
android:id="#+id/action_socialSearchFragment_to_userProfileFragment"
app:destination="#id/userProfileFragment" />
</fragment>
</navigation>
crashing:
--------- beginning of crash
2022-07-01 14:32:49.986 25363-25363/com.example.mywatchlist E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mywatchlist, PID: 25363
java.lang.IllegalStateException: View com.google.android.material.button.MaterialButton{3bedc11 VFED..C.. ...P.... 921,5-1440,173 #7f080237 app:id/contentContentSearchBtn} does not have a NavController set
at androidx.navigation.Navigation.findNavController(Navigation.kt:71)
at com.example.mywatchlist.contentSearchFragment$1.onClick(contentSearchFragment.java:73)
at android.view.View.performClick(View.java:7448)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1194)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2022-07-01 14:32:50.027 25363-25363/com.example.mywatchlist I/Process: Sending signal. PID: 25363 SIG: 9
thank you to all the helpers
can you please share the crashing error? It's hard to figure out the error. If you can also add how to reproduce the crash it can be very helpful
You forgot to initialize NavHostFragent
so kindly Initiliaze In your OnCreate
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager()
.findFragmentById(R.id. fragmentContainerView);
NavController navController = navHostFragment.getNavController();
and for the navigate one fragment to another fragment use navigate
homeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {navController.navigate(R.id. action_startFragment_to_registerFragment
}
});)
I created a View that has two recyclerviews inside.
Everything works correctly but I get that the two recyclerviews are scrollable.
I would like the two recyclerview to be shown in its maximum length to show all lines and for the scrolling of the view to work directly
if I set android: nestedScrollingEnabled = "false" the recyclerview is not shown totally long
what do i have to change?
Thanks
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
android:fillViewport="true"
android:background="#color/fond"
tools:context=".dossier.FicheDossier">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_gravity="center|top"
android:gravity="center|top">
<TextView
android:id="#+id/txtNomUsageDossierFragment"
android:layout_width="match_parent"
android:layout_height="86dp"
android:background="#drawable/fond_jaune_top"
android:fontFamily="#font/montserrat_bold"
android:gravity="center_horizontal"
android:onClick="backList"
android:paddingTop="21dp"
android:text="Dossiers"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="normal" />
<ImageView
android:id="#+id/btn_Back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="23dp"
app:srcCompat="#drawable/icone_arrow_left_blanc" />
<EditText
android:id="#+id/txtFindDocument"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="24dp"
android:layout_marginTop="62dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="4dp"
android:height="48dp"
android:background="#drawable/textedit_blanc_rounded_corners"
android:drawableLeft="#drawable/icone_recherche_jaune"
android:drawablePadding="6dp"
android:elevation="4dp"
android:ems="10"
android:hint="#string/txt_input_recherche"
android:inputType="text"
android:maxLines="1"
android:outlineSpotShadowColor="#color/jauneSombre"
android:paddingLeft="10dp"
android:scrollHorizontally="true"
android:textStyle="italic" />
<ProgressBar
android:id="#+id/progressBarTopListDocument"
style="?android:attr/progressBarStyle"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_marginTop="23dp"
android:layout_marginRight="23dp"
android:theme="#style/colorProgressBarTop"
/>
</RelativeLayout>
<TextView
android:id="#+id/msgListDocument"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginTop="32dp"
android:layout_marginBottom="2dp"
android:fontFamily="#font/montserrat"
android:text="#string/txt_msg_dossiers"
android:textColor="#color/neutre"
android:textStyle="bold"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list_classeurs_dossier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginTop="12dp"
android:layout_marginRight="24dp"
android:divider="#drawable/rectangle_border_bottom"
android:dividerHeight="1dp"
android:isScrollContainer="false"
android:nestedScrollingEnabled="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list_docs_dossier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:divider="#drawable/rectangle_border_bottom"
android:dividerHeight="1dp"
android:isScrollContainer="false"
android:nestedScrollingEnabled="false" />
</LinearLayout>
You have to use only one RecyclerView and use the type to manage which card you want to recall
public class RecyclerViewAdapterClasseursDocs extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final List<Document> documents;
private final List<Classeur> classeurs;
private final Context context;
public RecyclerViewAdapterClasseursDocs(List<Classeur> classeurs, List<Document> documents, Context context) {
this.classeurs = classeurs;
this.context = context;
this.documents = documents;
}
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
if (viewType == 0) {
return new ViewHolderClasseur(LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.classeur, parent, false));
}
return new ViewHolderDoc(LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.docs, parent, false));
}
#Override
public int getItemViewType(int position) {
if (position < this.classeurs.size()){
return 0;
} else {
return 1;
}
}
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
//Doc
if (holder.getItemViewType() == 0) {
//Classeur
ViewHolderClasseur c = (ViewHolderClasseur) holder;
final Classeur classeur = classeurs.get(position);
c.titleClasseur.setText(classeur.getNom());
} else {
ViewHolderDoc d = (ViewHolderDoc) holder;
final Document document = documents.get(position - classeurs.size());
d.titleDocument.setText(document.getIntitule());
}
}
#Override
public int getItemCount() {
return classeurs.size()+documents.size();
}
public static class ViewHolderClasseur extends RecyclerView.ViewHolder {
private final TextView titleClasseur;
private final View linearLayoutClasseur;
public ViewHolderClasseur(#NonNull View itemView) {
super(itemView);
linearLayoutClasseur = itemView.findViewById(R.id.rowClasseur);
titleClasseur = itemView.findViewById(R.id.txtClasseurTitle);
}
}
public static class ViewHolderDoc extends RecyclerView.ViewHolder {
private final TextView titleDocument;
public ViewHolderDoc(#NonNull View itemView) {
super(itemView);
itemView.findViewById(R.id.rowDocument);
titleDocument = itemView.findViewById(R.id.txtDocTitle);
itemView.findViewById(R.id.txtDocData);
}
}
}
I'm new to android development and trying to create a simple register application but the application crash every time I click the Register Here TextView. Other than that, I code the login button to try the calling of another activity but it has no respond after I click the button. I tried so hard to find the mistakes but I'm not sure that what I missed in the coding.
This is the main activity
package com.fyp4201.universityguide;
import android.content.Intent;
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.TabHost;
public class MainActivity extends AppCompatActivity {
TabHost tabHost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TabHost host = (TabHost) findViewById(R.id.tabHost);
host.setup();
//Tab 1
TabHost.TabSpec spec = host.newTabSpec("tab1");
spec.setContent(R.id.tab1);
spec.setIndicator("Home");
host.addTab(spec);
//Tab 2
spec = host.newTabSpec("tab2");
spec.setContent(R.id.tab2);
spec.setIndicator("Search Courses");
host.addTab(spec);
//Tab 3
spec = host.newTabSpec("tab3");
spec.setContent(R.id.tab3);
spec.setIndicator("Search University");
host.addTab(spec);
//Tab4
spec = host.newTabSpec("tab4");
spec.setContent(R.id.tab4);
spec.setIndicator("Compare Universities");
host.addTab(spec);
//Tab5
spec = host.newTabSpec("tab5");
spec.setContent(R.id.tab5);
spec.setIndicator("Ranking of Universities");
host.addTab(spec);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch( item.getItemId()){
//noinspection SimplifiableIfStatement
case R.id.action_settings: {
return true;
}
case R.id.action_login:{
Intent intent= new Intent(getApplicationContext(),LoginActivity.class);
startActivity(intent);
}
default:
return super.onOptionsItemSelected(item);
}
}}
This is codes for login activity
package com.fyp4201.universityguide;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class LoginActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TextView regis = (TextView) findViewById(R.id.register);
Button login = (Button) findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Homeafterlogin.class);
LoginActivity.this.startActivity(intent);
}
});
regis.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this, Register.class);
LoginActivity.this.startActivity(intent);
}
});
}}
This is codes for Register activity
package com.fyp4201.universityguide;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import android.widget.Toast;
import java.util.HashMap;
import java.util.Map;
public class Register extends AppCompatActivity {
private static final String REGISTER_URL = "http://jrfyp4201.site88.net/volleyRegister.php";
public static final String KEY_USERNAME = "username";
public static final String KEY_NAME = "name";
public static final String KEY_PASSWORD = "password";
public static final String KEY_EMAIL = "email";
public static final String KEY_CONTACTNO = "contactno";
private EditText etname,etuname,etpass,etconpass,etemail,etcontactno;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
etname= (EditText) findViewById(R.id.name);
etuname= (EditText) findViewById(R.id.uname);
etpass= (EditText) findViewById(R.id.pass);
etconpass= (EditText) findViewById(R.id.conpass);
etemail= (EditText) findViewById(R.id.email);
etcontactno= (EditText) findViewById(R.id.contactno);
}
public void onRegisterbtnClick(View view ){
registerUser();
}
public void registerUser(){
final String username = etuname.getText().toString().trim();
final String password = etpass.getText().toString().trim();
final String name = etname.getText().toString().trim();
final String email = etemail.getText().toString().trim();
final String contactno = etcontactno.toString().trim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Toast.makeText(Register.this,response,Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Register.this,error.toString(),Toast.LENGTH_LONG).show();
}
}){
#Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put(KEY_USERNAME,username);
params.put(KEY_PASSWORD,password);
params.put(KEY_NAME, name);
params.put(KEY_EMAIL, email);
params.put(KEY_CONTACTNO, contactno);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
}
This is the logcat error file
Process: com.fyp4201.universityguide, PID: 20646
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fyp4201.universityguide/com.fyp4201.universityguide.Register}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2264)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.access$1100(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:895)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:711)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.fyp4201.universityguide.Register.onCreate(Register.java:20)
at android.app.Activity.performCreate(Activity.java:5340)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.access$1100(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:895)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:711)
at dalvik.system.NativeStart.main(Native Method)
XML files of register activity
<?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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.fyp4201.universityguide.Register"
tools:showIn="#layout/activity_register">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name :"
android:id="#+id/textView2" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editname"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username :"
android:id="#+id/textView3" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edituname"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password :"
android:id="#+id/textView4" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editpass"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm Password :"
android:id="#+id/textView7" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editconpass"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-mail address :"
android:id="#+id/textView5" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editemail"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Number :"
android:id="#+id/textView6" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/editcontactno"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:id="#+id/registerbtn"
android:layout_gravity="center_horizontal"
android:onClick="onRegisterbtnClick" />
</LinearLayout>
XML file of login activity
<?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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.fyp4201.universityguide.LoginActivity"
tools:showIn="#layout/activity_login2">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:id="#+id/textView1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/loginuname" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:id="#+id/textView" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/loginpass" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/login"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:focusableInTouchMode="false"
android:onClick="onLoginClick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Register Here!"
android:id="#+id/register"
android:layout_gravity="center_horizontal"
android:textColor="#color/accent_material_light"
android:clickable="true"
android:onClick="onRegisterClick" />
</LinearLayout>
Please tell me what I missed. Thank you.
Check all the ids in the xml files and correct their name in java.
It seems like you are referencing an id of another xml file thats not associated with this activity like you might be refering a username field of login xml file in registration activity and vice versa
Nvm, i fixed the problem. There's no problem with the codings just the application is not updated after changes had been made. It is fixed after i clean and rebuild the project. Thank you .
I am facing a weird problem related to view not found but everything seems to be right with the code (at least to me). Infact the program was working fine till some time back. I am not sure what change that i made causing this issue. Could anyone of you point me the problem? Thank you.
The below is the exception trace:
FATAL EXCEPTION: main
Process: co.mycompany, PID: 3923
java.lang.RuntimeException: Unable to start activity ComponentInfo{co.mycompany/co.mycompany.activities.MainActivity}: java.lang.RuntimeException: Unable to bind views for co.mycompany.activities.MainActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5065)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to bind views for co.mycompany.activities.MainActivity
at butterknife.ButterKnife.bind(ButterKnife.java:322)
at butterknife.ButterKnife.bind(ButterKnife.java:237)
at co.mycompany.activities.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2165)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5065)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Required view 'thUserProfilePic' with ID 2131558656 for field 'mUserProfilePic' was not found. If this view is optional add '#Nullable' annotation.
at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:140)
at co.mycompany.activities.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:17)
at co.mycompany.activities.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:8)
at butterknife.ButterKnife.bind(ButterKnife.java:319)
at butterknife.ButterKnife.bind(ButterKnife.java:237)
at co.mycompany.activities.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2165)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5065)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
MainActivity.class
#Bind(R.id.thUserProfilePic)
CircleImageView mUserProfilePic;
#Bind(R.id.thUserDisplayName)
TextView mUserDisplayName;
#Bind(R.id.editProfileLink)
ImageView editProfileLink;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerLayout.setDrawerListener(toggle);
toggle.syncState();
mNavigationView.setNavigationItemSelectedListener(this);
navigate(AppScreen.HOME);
}
R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">
<include layout="#layout/app_bar_main" android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView android:id="#+id/nav_view"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main" app:menu="#menu/activity_main_drawer"
android:background="#color/white"/>
</android.support.v4.widget.DrawerLayout>
R.layout.nav_header_main
<?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="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
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:theme="#style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/editProfileLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_edit_white_24dp"
android:layout_gravity="end|right"/>
<include layout="#layout/user_thumbnail_large"/>
</LinearLayout>
R.layout.user_thumnail_large
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:id="#+id/userThumbnailLargeContainer">
<de.hdodenhof.circleimageview.CircleImageView android:layout_width="75dp" android:layout_height="75dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:src="#drawable/ic_face_white_48dp" android:id="#+id/thUserProfilePic" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing" android:text="John"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:id="#+id/thUserDisplayName"
android:textColor="#color/textColorSecondary"/>
</LinearLayout>
I am into second day of research and could not able to figure out what the issue is.
The issue is with support Library version. I was getting the above error since i upgraded support library to 23 version.
The below link has the solution.
NavigationView get/find header layout