Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
This week's book giveaway is in the
Design
forum.
We're giving away four copies of
Experimentation for Engineers: From A/B testing to Bayesian optimization
and have David Sweet on-line!
See
this thread
for details.
Win a copy of
Experimentation for Engineers: From A/B testing to Bayesian optimization
this week in the
Design
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
null pointer exception when i add style to my layout xml file
shawn peter
Ranch Hand
Posts: 1325
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
below is my xml file
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ViewStub android:id="@+id/vsHeader" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inflatedId="@+id/header" android:layout="@layout/header" /> <LinearLayout android:id="@+id/header" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dp" > <RelativeLayout android:id="@+id/date" android:layout_width="fill_parent" android:layout_height="60dp" android:layout_marginTop="20dp" android:orientation="horizontal" > <TextView android:id="@+id/fromDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="20dp" android:layout_marginTop="20dp" android:text="From" android:textSize="14sp" /> <Button android:id="@+id/btnFromDate" style="@style/RoundedButtonAsh" android:layout_height="45dp" android:layout_gravity="center" android:layout_marginTop="10dip" android:layout_toRightOf="@+id/fromDate" android:onClick="onButtonClicker" android:text="Select date" android:width="200dp" /> </RelativeLayout> <RelativeLayout android:id="@+id/date" android:layout_width="fill_parent" android:layout_height="60dp" android:layout_marginTop="20dp" android:orientation="horizontal" > <TextView android:id="@+id/toDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="35dp" android:layout_marginTop="20dp" android:text="To" android:textSize="14sp" /> <Button android:id="@+id/btnToDate" style="@style/RoundedButtonAsh" android:layout_height="45dp" android:layout_gravity="center" android:layout_marginTop="10dip" android:layout_toRightOf="@+id/toDate" android:onClick="onButtonClicker" android:text="Select date" android:width="200dp" /> </RelativeLayout> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/btnSubmit" style="@style/RoundedButtonAsh" android:layout_height="45dp" android:layout_gravity="center" android:layout_marginLeft="65dip" android:onClick="onButtonClicker" android:text="@string/Submit" android:width="200dp" /> </LinearLayout> </LinearLayout>
below is the
java
class
package com.android.member; import com.android.dashboard.Activity_Exit; import com.android.dashboard.Activity_Help; import com.android.dashboard.DashBoardActivity; import com.android.dashboard.Global; import com.android.db.DatabaseHandler; import com.android.db.ShiftDelegate; import com.android.lead.PM_Admin; import com.android.lead.PM_Approve; import com.android.lead.PM_Dashbord; import com.android.lead.PM_Shift; import com.android.loginactivity.LoginActivity; import com.android.loginactivity.R; import com.android.shift.MainActivity; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class Member_Home extends DashBoardActivity { private String username; private String password; private DatabaseHandler db; private TextView request; private ShiftDelegate delegate ; private SharedPreferences sp; private Global global; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { setContentView(R.layout.member_home); setHeader(getString(R.string.HomeActivityTitle), false, true); global = ((Global) getApplicationContext()); sp = PreferenceManager .getDefaultSharedPreferences(this); db = new DatabaseHandler(this); request = (TextView) findViewById(R.id.txtChangeShift); if(db.isRequestApproved(global.getUsername().toString().trim())){ Editor edit = sp.edit(); edit.putString("RequestApproved"+ global.getUsername().toString().trim(), "RequestApproved"); edit.commit(); } if(db.isResponseApproved((global.getUsername().toString().trim()))){ Editor edit = sp.edit(); edit.putString("ResponseApproved"+ global.getUsername().toString().trim(), "ResponseApproved"); edit.commit(); } if (db.isNewRequest(global.getUsername())) { ShiftDelegate delegate = db.getDelegate(global.getUsername() .toString().trim()); request.setVisibility(View.VISIBLE); Editor edit = sp.edit(); edit.putString("Delegation" + global.getUsername().toString().trim(), "VISIBLE"); edit.commit(); } // Global global = ((Global) getApplicationContext()); // global.setUsername((uername).getText().toString()); // global.setPassword((password).getText().toString()); db.close(); } catch (Exception e) { e.printStackTrace(); } } @Override public void onBackPressed() { Intent intent = new Intent(getApplicationContext(), LoginActivity.class); startActivity(intent); return; } @Override public void onResume() { super.onResume(); db = new DatabaseHandler(this); if (db.isNewRequest(global.getUsername())) { SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences(this); ShiftDelegate delegate = db.getDelegate(global.getUsername() .toString().trim()); String status = sp.getString("Delegation" + global.getUsername().toString().trim(), "VISIBLE"); if (status.equalsIgnoreCase("VISIBLE")) { request.setVisibility(View.VISIBLE); }else{ request.setVisibility(View.GONE); } } db.close(); // setLike(); // request.setVisibility(View.GONE); } public void onButtonClicker(View v) { Intent intent; switch (v.getId()) { case R.id.main_btn_shift: // intent = new Intent(this, Activity_Shift.class); intent = new Intent(this, Member_Shift.class); startActivity(intent); break; case R.id.main_btn_leave: intent = new Intent(this, Member_Leave.class); startActivity(intent); break; case R.id.main_btn_allowances: intent = new Intent(this, Member_Allowance.class); startActivity(intent); break; case R.id.main_btn_delegate: intent = new Intent(this, Member_Shift_Swap.class); startActivity(intent); break; case R.id.main_btn_preference: intent = new Intent(this, Member_Shift_preference.class); startActivity(intent); break; case R.id.main_btn_player: intent = new Intent(this, Member_Player.class); startActivity(intent); break; case R.id.txtChangeShift: intent = new Intent(this, Member_ShowSwap.class); startActivity(intent); break; default: break; } } }
but when i change the my xml file first part as below(Add the style " android:background="@style/page_background_wh") it give me exception
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@style/page_background_wh" android:orientation="vertical" >
below is exception
10-29 11:04:28.998: W/System.err(12659): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown> 10-29 11:04:29.008: W/System.err(12659): at android.view.LayoutInflater.createView(LayoutInflater.java:518) 10-29 11:04:29.008: W/System.err(12659): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 10-29 11:04:29.008: W/System.err(12659): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) 10-29 11:04:29.008: W/System.err(12659): at android.view.LayoutInflater.inflate(LayoutInflater.java:386) 10-29 11:04:29.008: W/System.err(12659): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 10-29 11:04:29.008: W/System.err(12659): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 10-29 11:04:29.008: W/System.err(12659): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227) 10-29 11:04:29.008: W/System.err(12659): at android.app.Activity.setContentView(Activity.java:1657) 10-29 11:04:29.008: W/System.err(12659): at com.android.member.Member_Home.onCreate(Member_Home.java:40) 10-29 11:04:29.008: W/System.err(12659): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 10-29 11:04:29.008: W/System.err(12659): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 10-29 11:04:29.008: W/System.err(12659): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 10-29 11:04:29.008: W/System.err(12659): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 10-29 11:04:29.008: W/System.err(12659): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 10-29 11:04:29.008: W/System.err(12659): at android.os.Handler.dispatchMessage(Handler.java:99) 10-29 11:04:29.008: W/System.err(12659): at android.os.Looper.loop(Looper.java:130) 10-29 11:04:29.008: W/System.err(12659): at android.app.ActivityThread.main(ActivityThread.java:3701) 10-29 11:04:29.008: W/System.err(12659): at java.lang.reflect.Method.invokeNative(Native Method) 10-29 11:04:29.008: W/System.err(12659): at java.lang.reflect.Method.invoke(Method.java:507) 10-29 11:04:29.008: W/System.err(12659): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 10-29 11:04:29.008: W/System.err(12659): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 10-29 11:04:29.008: W/System.err(12659): at dalvik.system.NativeStart.main(Native Method) 10-29 11:04:29.008: W/System.err(12659): Caused by: java.lang.reflect.InvocationTargetException 10-29 11:04:29.008: W/System.err(12659): at java.lang.reflect.Constructor.constructNative(Native Method) 10-29 11:04:29.008: W/System.err(12659): at java.lang.reflect.Constructor.newInstance(Constructor.java:415) 10-29 11:04:29.008: W/System.err(12659): at android.view.LayoutInflater.createView(LayoutInflater.java:505) 10-29 11:04:29.008: W/System.err(12659): ... 21 more 10-29 11:04:29.008: W/System.err(12659): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070000 a=-1 r=0x7f070000} 10-29 11:04:29.018: W/System.err(12659): at android.content.res.Resources.loadDrawable(Resources.java:1692) 10-29 11:04:29.018: W/System.err(12659): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 10-29 11:04:29.018: W/System.err(12659): at android.view.View.<init>(View.java:1975) 10-29 11:04:29.018: W/System.err(12659): at android.view.View.<init>(View.java:1923) 10-29 11:04:29.018: W/System.err(12659): at android.view.ViewGroup.<init>(ViewGroup.java:314) 10-29 11:04:29.018: W/System.err(12659): at android.widget.LinearLayout.<init>(LinearLayout.java:124) 10-29 11:04:29.018: W/System.err(12659): ... 24 more 10-29 11:04:29.018: D/AndroidRuntime(12659): Shutting down VM 10-29 11:04:29.018: W/dalvikvm(12659): threadid=1: thread exiting with uncaught exception (group=0x2aac8578) 10-29 11:04:29.028: E/AndroidRuntime(12659): FATAL EXCEPTION: main 10-29 11:04:29.028: E/AndroidRuntime(12659): java.lang.RuntimeException: Unable to resume activity {com.android.loginactivity/com.android.member.Member_Home}: java.lang.NullPointerException 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2141) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2156) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.os.Handler.dispatchMessage(Handler.java:99) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.os.Looper.loop(Looper.java:130) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.ActivityThread.main(ActivityThread.java:3701) 10-29 11:04:29.028: E/AndroidRuntime(12659): at java.lang.reflect.Method.invokeNative(Native Method) 10-29 11:04:29.028: E/AndroidRuntime(12659): at java.lang.reflect.Method.invoke(Method.java:507) 10-29 11:04:29.028: E/AndroidRuntime(12659): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 10-29 11:04:29.028: E/AndroidRuntime(12659): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 10-29 11:04:29.028: E/AndroidRuntime(12659): at dalvik.system.NativeStart.main(Native Method) 10-29 11:04:29.028: E/AndroidRuntime(12659): Caused by: java.lang.NullPointerException 10-29 11:04:29.028: E/AndroidRuntime(12659): at com.android.member.Member_Home.onResume(Member_Home.java:100) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.Activity.performResume(Activity.java:3832) 10-29 11:04:29.028: E/AndroidRuntime(12659): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2131) 10-29 11:04:29.028: E/AndroidRuntime(12659): ... 12 more
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
need to find distance between given two cities
how to align radio button groups
how to give Edittext and button to half of the screen width?
android uncaught handler: thread main exiting due to uncaught exception
how to get a longitude & latitude from a given address
More...