I have a SimpleAdapter with filtering inputSearch and clickable items (which I get from MySQL database).
Sometimes when I lunch my project there is an error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brzozowski.marcin.inzynierka/com.brzozowski.marcin.inzynierka.activities.ChooseGroupActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.widget.Filter android.widget.SimpleAdapter.getFilter()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3947)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.widget.Filter android.widget.SimpleAdapter.getFilter()' on a null object reference
at com.brzozowski.marcin.inzynierka.activities.ChooseGroupActivity$2.onTextChanged(ChooseGroupActivity.java:103)
at android.widget.TextView.sendOnTextChanged(TextView.java:7679)
at android.widget.TextView.setText(TextView.java:4060)
at android.widget.TextView.setText(TextView.java:3915)
at android.widget.EditText.setText(EditText.java:85)
at android.widget.TextView.setText(TextView.java:3890)
at android.widget.TextView.onRestoreInstanceState(TextView.java:3790)
at android.view.View.dispatchRestoreInstanceState(View.java:13740)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2893)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2893)
at android.view.View.restoreHierarchyState(View.java:13718)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2009)
at android.app.Activity.onRestoreInstanceState(Activity.java:1023)
at android.app.ListActivity.onRestoreInstanceState(ListActivity.java:219)
at android.app.Activity.performRestoreInstanceState(Activity.java:978)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1162)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3947)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
When I launch the application next time, its ok.
So the error occurs every second launch.
Remove simpleAdapter initialization from onResume.
In your onCreate
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initAdapter();
}
private void initAdapter(){
simpleAdapter = new SimpleAdapter(this, employeeList,
android.R.layout.simple_list_item_1,
new String[] { "groups" }, new int[] { android.R.id.text1 });
listView.setAdapter(simpleAdapter);}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(simpleAdapter == null){
initAdapter();
}
simpleAdapter.getFilter().filter(s);
}
You create the SimpleAdapter in onResume, but what's happening here is that you have set your textChangedListener in onCreate. After onCreate is called, Android restores the view state, including the text in your view. This triggers the text change listener before onResume runs and creates the SimpleAdapter. I think you will be fine to move your SimpleAdapter setup to onCreate, and then it should just work.
Related
Recently my android app crash when it tested on real device. but it works fine while tested on emulator. My app has fragment that implement RecyclerView and when the item in RecyclerView clicked it will start new Detail activity, and it crash when back press button clicked. I've role back to the previous commit that works on device but it still crashing.
this the Error Log :
07-10 14:07:15.146 12250-12250/com.luckyendey.polymarkapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.luckyendey.polymarkapp, PID: 12250
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.luckyendey.polymarkapp/com.luckyendey.polymarkapp.main.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.luckyendey.polymarkapp.bonsementara.BonSementaraHeaderTabOpenFragment$LayoutManagerType.ordinal()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.luckyendey.polymarkapp.bonsementara.BonSementaraHeaderTabOpenFragment$LayoutManagerType.ordinal()' on a null object reference
at com.luckyendey.polymarkapp.bonsementara.BonSementaraHeaderTabOpenFragment.setRecyclerViewLayoutManager(BonSementaraHeaderTabOpenFragment.java:98)
at com.luckyendey.polymarkapp.bonsementara.BonSementaraHeaderTabOpenFragment.onCreateView(BonSementaraHeaderTabOpenFragment.java:60)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2900)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2207)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1326)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2900)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:603)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
This is My code :
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.tab_purchase_request_open, container, false);
access_token = GlobalMethod.getPref("access_token",getContext());
presenter = new PurchaseRequestHeaderOpenPresenter(this);
presenter.getListDataPurchaseRequest(access_token,"");
presenter.getRequestType(access_token);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_purchase_request_open);
mLayoutManager = new LinearLayoutManager(getActivity());
mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;
if (savedInstanceState != null) {
// Restore saved layout manager type.
mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState
.getSerializable(KEY_LAYOUT_MANAGER); // this is return null that causing the error
}
setRecyclerViewLayoutManager(mCurrentLayoutManagerType);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_purchase_request_open);
swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary,R.color.colorAccent,R.color.colorPrimary);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
presenter.getListDataPurchaseRequest(access_token,"");
}
});
return view;
}
On emulator onCreateView not trigger when back press clicked on detail activity, but in device it call again.
I've been solved this problem by turning off Don't keep activities under Developer Options. I forgot that I was enabled it and now my app works great.
I now get a new error.
This is my code:
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int i, long id) {
Toast.makeText(getApplicationContext(), beaconAdap.getItem(i).toString() + " Added to history", Toast.LENGTH_SHORT).show();
historyBeacons.add(beaconAdap.getItem(i).toString());
Intent intent = new Intent(getBaseContext(), HistoryActivity.class);
intent.putStringArrayListExtra("beacons", historyBeacons);
startActivity(intent);
return true;
}
});
}
So i add the int i to an arraylist, i have tested that it goes in and it does. Then a start a new intent for the history activity and send the arraylist over.
This is the code in history:
ListView historyLv = (ListView) findViewById(R.id.historyView);
ArrayAdapter historyAdap;
ArrayList<String> historyBeacons = getIntent().getExtras().getStringArrayList("beacons");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
historyAdap = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, historyBeacons);
historyLv.setAdapter(historyAdap);
}
But i get this error:
03-18 17:44:41.238 18641-18641/nsa.com.museum E/AndroidRuntime: FATAL EXCEPTION: main
Process: nsa.com.museum, PID: 18641
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{nsa.com.museum/nsa.com.museum.HistoryActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:120)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:151)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:33)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:203)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at nsa.com.museum.HistoryActivity.<init>(HistoryActivity.java:12)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-18 17:44:43.362 18846-18846/nsa.com.museum W/System: ClassLoader referenced unknown path: /data/app/nsa.com.museum-2/lib/x86_64
can You show the erro please
and I guess you forget to add
ListAdapter.notifyDataSetChanged();
after you add value to lisy
.........................................................
NullPointerException
this erro shows in Android cause you may not Initialized the Adapter
make sure you Initialized the 2nd adapter
I have no underlined code, but as soon as i start my app on emulator, i'm receiving these errors.
FATAL EXCEPTION: main
Process: com.milos.sportisa, PID: 2735
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.milos.sportisa/com.milos.sportisa.SplashActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTypeface(android.graphics.Typeface)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTypeface(android.graphics.Typeface)' on a null object reference
at com.milos.sportisa.SplashActivity.onCreate(SplashActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
And this is my SplashActivity:
public class SplashActivity extends AppCompatActivity {
private TextView etSportisa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
/* ButterKnife.inject(this);
mProgressBar.setIndeterminateDrawable(new foldingCirclesDrawable.Builder(this)
.build());
mProgressBar.setIndeterminateDrawable(new foldingCirclesDrawable.Builder(this)
.colors(getResources().getIntArray(R.array.colors) //Array of 4 colors
.build()); */
Typeface myTypeFace = Typeface.createFromAsset(getAssets(), "fonts/esp_ital.ttf");
etSportisa.setTypeface(myTypeFace);
etSportisa = (TextView) findViewById(R.id.tv_sportisa);
final ProgressDialog pd = new ProgressDialog(SplashActivity.this);
pd.setMessage("Učitavanje...");
pd.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// Actions to do after 10 seconds
pd.dismiss();
Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
}
}, 2000);
}
}
Special font is added in assets\font folder. I also added an image for the loading screen but i think that the font is cousin those issues
Make the following changes to your code:
Typeface myTypeFace = Typeface.createFromAsset(getAssets(), "fonts/esp_ital.ttf");
etSportisa = (TextView) findViewById(R.id.tv_sportisa);
etSportisa.setTypeface(myTypeFace);
After initialization, you can do any operation with any layout.
The problem is here:
etSportisa is null
set it after you findViewByID
Typeface myTypeFace = Typeface.createFromAsset(getAssets(), "fonts/esp_ital.ttf");
etSportisa = (TextView) findViewById(R.id.tv_sportisa);
etSportisa.setTypeface(myTypeFace);
Some time ther is not error its run without error but most of time got error in this code, I try many thing for this. I try call this code on onStart() and I try this on onActivityCreted() too. but i get same error. This is my coding for show previous chat. I got error in limit().
final ListView listView = getListView();
mChatListAdapter = new FirebaseListAdapter<>(mFirebaseRef.limit(50), Chat.class, R.layout.chat_item, R.layout.chat_item_other,
R.layout.third_layout_chat, R.layout.fourth_layout_chat, getActivity(), chat_id);
listView.setAdapter(mChatListAdapter);
mChatListAdapter.registerDataSetObserver(new DataSetObserver() {
#Override
public void onChanged() {
super.onChanged();
listView.setSelection(mChatListAdapter.getCount() - 1);
}
});
This is error.
FATAL EXCEPTION: main Process: com.socialapp.android, PID: 8112 Theme: themes:{} java.lang.RuntimeException: Unable to start activity ComponentInfo{com.socialapp.android/com.socialapp.chat.ChatViewActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.firebase.client.Query com.firebase.client.Firebase.limit(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.firebase.client.Query com.firebase.client.Firebase.limit(int)' on a null object reference
at com.socialapp.chat.ChatViewFragment.onStart(ChatViewFragment.java:609)
at android.app.Fragment.performStart(Fragment.java:2244)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1002)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1958)
at android.app.FragmentController.dispatchStart(FragmentController.java:163)
at android.app.Activity.performStart(Activity.java:6274)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I am creating a restaurant app that requires an expandable listview to show a menu for the waiter to take a customer's menu. The app is crashing and I think it has something to do with the code below:
public class Menu extends AppCompatActivity {
HashMap < String, List < String >> Food_menu;
List < String > Food_list;
ExpandableListView Exp_list;
FoodMenuAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Exp_list = (ExpandableListView) findViewById(R.id.exp_list);
Food_menu = DataProvider.getInfo();
Food_list = new ArrayList < String > (Food_menu.keySet());
adapter = new FoodMenuAdapter(this, Food_menu, Food_list);
Exp_list.setAdapter(adapter);
}
}
When I debugged the app, it said that:
Exp_list
Food_menu
Food_list
were all coming back as null. I'm new to android studios and I'm not sure how to remedy the problem. Any help would be greatly appreciated, thanks.
Logcat:
04-11 22:05:53.841 1960-1960/com.example.ben.restaurantapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ben.restaurantapp, PID: 1960
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ben.restaurantapp/com.example.ben.restaurantapp.Menu}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)' on a null object reference
at com.example.ben.restaurantapp.Menu.onCreate(Menu.java:38)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
I think the second parameter of your FoodMenuAdapter has to be a resource layout file.
For example:
Food Food_menu = DataProvider.getInfo();
adapter = new FoodMenuAdapter(this, R.layout.your_xml_layout_here, Food_list);
Exp_list = (ExapandableListView) findViewById(R.id.exp_list);
Exp_list.setAdapter(adapter);
Where your_xml_layout_here is the layout that all the information will be displayed on. Keep in mind that an adapter is the middleman of information and what you see on your application screen.
From your logcat you can see the exact problem:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)' on a null object reference
which means that at the point you try to use setAdapter method on the Exp_List, the said variable is null.
What you can do from here on is to check if your layout activity_main actually contains an ExpandableListView with an id of exp_list (maybe post your layout?).
Your question should not be android studio null error as the null has nothing to do with Android Studio - it comes from the programming language, in this specific case - Java.
You can learn how to fix NullPointerExceptions here.