Error while Inflating class? - java

I migrated a project from Eclipse to Android Studio. In my project, I have added this library.
I have added the library as a dependency in my gradle file. I can import the library from my class.But it shows this
android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
while running the app.
Note - It worked fine while running it from Eclipse.
gradle
apply plugin: 'android'
dependencies {
// compile fileTree(dir: 'libs', include: '*.jar')
compile project(':RemoteIt Protocol')
compile project(':android-support-v7-appcompat')
compile files('libs/gama_wheel_v1.0.jar')
compile files('libs/PayPalAndroidSDK.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Layout
<?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"
>
<com.digitalaria.gama.wheel.Wheel
android:id="#+id/wheel"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.digitalaria.gama.wheel.Wheel>
</LinearLayout>
Class
import com.digitalaria.gama.wheel.Wheel;
import com.digitalaria.gama.wheel.WheelAdapter;
public class Home extends MainActivity implements OnClickListener
{
private RemoteIt application;
private SharedPreferences preferences;
#Override
protected void onCreate(Bundle savedInstanceState)
{
this.application = (RemoteIt) this.getApplication();
this.preferences = this.application.getPreferences();
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(s);
this.checkOnCreate();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View contentView = inflater.inflate(R.layout.home, null, false);
mDrawer.addView(contentView, 0);
init();
wheel();
}
private void wheel()
{
wheel.setOnItemClickListener(new WheelAdapter.OnItemClickListener()
{
#Override
public void onItemClick(WheelAdapter<?> parent, View view, int position, long id)
{
switch (position)
{
case 0:
Intent ac = new Intent(Home.this, ConnectionListActivity.class);
startActivity(ac);
break;
case 1:
Intent b = new Intent(Home.this, ControlActivity.class);
startActivity(b);
break;
case 2:
Intent c = new Intent(Home.this, FileExplorerActivity.class);
startActivity(c);
// this.toggleKeyboard();
break;
case 3:
Intent d = new Intent(Home.this, Presentation.class);
startActivity(d);
break;
case 4:
Intent e = new Intent(Home.this, Media.class);
startActivity(e);
break;
case 5:
Intent f = new Intent(Home.this, Shortcuts.class);
startActivity(f);
break;
case 6:
Intent g = new Intent(Home.this, Browser.class);
startActivity(g);
break;
}
}
});
}
private Wheel wheel;
private Resources res;
private int[] icons = {
R.drawable.conn, R.drawable.mouse, R.drawable.file, R.drawable.present, R.drawable.media, R.drawable.shortc, R.drawable.browser
};
private void init()
{
res = getApplicationContext().getResources();
wheel = (Wheel) findViewById(R.id.wheel);
wheel.setItems(getDrawableFromData(icons));
wheel.setWheelDiameter((int) getResources().getDimension(R.dimen.diameter));
}
private Drawable[] getDrawableFromData(int[] data)
{
Drawable[] ret = new Drawable[data.length];
for (int i = 0; i < data.length; i++)
{
ret[i] = res.getDrawable(data[i]);
}
return ret;
}
LogCat
Process: com.RemoteIt.client, PID: 1825
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.RemoteIt.client/com.RemoteIt.client.activity.Home}: android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
at android.content.res.TypedArray.getInteger(TypedArray.java:368)
at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:83)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:68)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
Wheel.java
public final class Wheel extends android.widget.FrameLayout {
public static final int CCW = -1;
public static final int CW = 1;
private com.digitalaria.gama.wheel.WheelBehavior _wheelBehavior;
private android.view.ViewStub _backgroundViewDummy;
protected android.view.View _backgroundView;
protected boolean _hasBackgroundImage;
private android.widget.FrameLayout.LayoutParams params;
private int _reservedPositionLeft;
private int _reservedPositionTop;
private boolean isLayout;
private int _storedLeft;
private int _storedTop;
private int _storedRight;
private int _storedBottom;
private int _centerX;
private int _centerY;
public Wheel(android.content.Context context) { /* compiled code */ }
public Wheel(android.content.Context context, android.util.AttributeSet attrs) { /* compiled code */ }
public Wheel(android.content.Context context, android.util.AttributeSet attrs, int defStyle) { /* compiled code */ }
protected void onLayout(boolean changed, int l, int t, int r, int b) { /* compiled code */ }
public void addView(android.view.View child) { /* compiled code */ }
public void addView(android.view.View child, int index) { /* compiled code */ }
public void removeView(android.view.View child) { /* compiled code */ }
public void removeViewAt(int index) { /* compiled code */ }
public float getCenterX() { /* compiled code */ }
public float getCenterY() { /* compiled code */ }
public final void setOnItemClickListener(com.digitalaria.gama.wheel.WheelAdapter.OnItemClickListener listener) { /* compiled code */ }
public final com.digitalaria.gama.wheel.WheelAdapter.OnItemClickListener getOnItemClickListener() { /* compiled code */ }
public final void setOnWheelRotationListener(com.digitalaria.gama.wheel.WheelAdapter.OnWheelRotationListener listener) { /* compiled code */ }
public final com.digitalaria.gama.wheel.WheelAdapter.OnWheelRotationListener getOnWheelRotationListener() { /* compiled code */ }
public void setOnItemSelectionUpdatedListener(com.digitalaria.gama.wheel.WheelAdapter.OnItemSelectionUpdatedListener listener) { /* compiled code */ }
public void setPosition(int left, int top) { /* compiled code */ }
public void setSelectionAngle(int angle) { /* compiled code */ }
public void setItems(android.content.res.TypedArray items) { /* compiled code */ }
public void setItems(android.graphics.drawable.Drawable[] drawables) { /* compiled code */ }
public void setWheelDiameter(int diameter) { /* compiled code */ }
public void setWheelBackground(int inflatedId, int layoutResource) { /* compiled code */ }
public void setRotatedItem(boolean flag) { /* compiled code */ }
public void configureWheelBackground(int initRotationAngle, boolean rotatedItem) { /* compiled code */ }
public void configureWheelBackground(boolean rotatedItem) { /* compiled code */ }
protected boolean hasBackgroundImage() { /* compiled code */ }
public void setTouchArea(int from, int to) { /* compiled code */ }
public int nextItem() { /* compiled code */ }
public int previousItem() { /* compiled code */ }
public boolean isRotationFinished() { /* compiled code */ }
public void flingStartUsingAngle(float angle) { /* compiled code */ }
public void flingStartUsingVelocity(int vx, int vy, boolean scroolToSlot) { /* compiled code */ }
public void flingStartUsingVelocityWithDirection(int vx, int vy, int direction) { /* compiled code */ }
public int getSelectedItem() { /* compiled code */ }
public int getSelectedItem(boolean stopScroll) { /* compiled code */ }
public boolean setSelectedItem(int index) { /* compiled code */ }
public void setItemClickEventAtSelectionPosition(boolean enable) { /* compiled code */ }
public boolean getItemClickEventAtSelectionPosition() { /* compiled code */ }
public void setEnabled(boolean enabled) { /* compiled code */ }
public boolean isLayouted() { /* compiled code */ }
}

The relevant exception :
Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
at android.content.res.TypedArray.getInteger(TypedArray.java:368)
at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
WheelBehavior.java, line 117
setWheelDiameter(arr.getInteger(R.styleable.Wheel_wheel_diameter, Configuration.DEFAULT_WHEEL_DIAMETER));
Here are the styleable attributes :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Wheel">
<attr name="wheel_rotation_duration" format="integer"/> <!-- default:400 -->
<attr name="wheel_diameter" format="integer"/> <!-- default:250 -->
<attr name="items" format="integer"/>
<attr name="item_selected_index" format="integer"/>
</declare-styleable>
</resources>
wheel_diameter must be defined somewhere in your project, with something else than a integer inside it. That's why it crashed. But according to your layout, it is not. Try a global search on the string wheel_diameter

I think my answer is a rave, but you can try to set layout_gravity="center" or layout_gravity="center_horizontal" cause I think the creator of the library tries to get this property.

Try to replace this code :
compile files('libs/gama_wheel_v1.0.jar')
compile files('libs/PayPalAndroidSDK.jar')
With this code :
compile fileTree(dir: 'libs', include: '*.jar')

Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
at android.content.res.TypedArray.getInteger(TypedArray.java:368)
at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:83)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:68)
I think you need to look into this one. Not sure if Wheel is something you made or downloaded, but it seems to be having a problem in its setup.

Related

I initialize a TextView before runtime because the views are not set yet

I write this counter but when I lunch the app get crashed I don't now where the error some help and thank you tell where is the Error here or how can I do code in right way
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
TextView txt = (TextView)findViewById(R.id.textView);
count i;
public void bu1(View view) {
starrtime();
}
public void bu2(View view) {
i.cancel();
}
void starrtime(){
i = new count(100,1000);
i.start();
}
public class count extends CountDownTimer {
public count(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
#Override
public void onTick(long millisUntilFinished) {
txt.setText(String.valueOf(millisUntilFinished));
}
#Override
public void onFinish() {
txt.setText("Done");
}
}
}
this my log cat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kira.counter, PID: 4598
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.kira.counter/com.example.kira.counter.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.app.AppCompatDelegateImplBase.(AppCompatDelegateImplBase.java:116)
at android.support.v7.app.AppCompatDelegateImplV9.(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.(AppCompatDelegateImplV14.java:50)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at com.example.kira.counter.MainActivity.(MainActivity.java:23)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
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:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 
I believe you can not initialize a TextView before runtime because the views are not set yet. Classes should be capitalized. Try this.
public class MainActivity extends AppCompatActivity{
private TextView txt;
private Count i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView)findViewById(R.id.textView);
}
}

Android get Status Bar Height giving java.lang.ExceptionInInitializerError

Additional Information (the original question below)
After following #ρяσѕρєяK advice in the comments section, I am getting the same error on another file (SizeNotifierRelativeLayout.java) and the error occurs at line 44, which is super.onLayout(changed, l, t, r, b);. The code for this file and the logcat are as follows:
SizeNotifierRelativeLayout.java
package com.app.name.widgets;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import android.widget.RelativeLayout;
import com.app.name.AndroidUtilities;
public class SizeNotifierRelativeLayout extends RelativeLayout {
private Rect rect = new Rect();
public SizeNotifierRelativeLayoutDelegate delegate;
public abstract interface SizeNotifierRelativeLayoutDelegate {
public abstract void onSizeChanged(int keyboardHeight);
}
public SizeNotifierRelativeLayout(Context context) {
super(context);
}
public SizeNotifierRelativeLayout(Context context, android.util.AttributeSet attrs) {
super(context, attrs);
}
public SizeNotifierRelativeLayout(Context context, android.util.AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (delegate != null) {
View rootView = this.getRootView();
int usableViewHeight = rootView.getHeight() - AndroidUtilities.statusBarHeight - AndroidUtilities.getViewInset(rootView);
this.getWindowVisibleDisplayFrame(rect);
int keyboardHeight = usableViewHeight - (rect.bottom - rect.top);
delegate.onSizeChanged(keyboardHeight);
}
}
}
logcat
10-15 09:09:57.918 23530-23530/? W/System.err﹕ at com.app.name.widgets.SizeNotifierRelativeLayout.onLayout(SizeNotifierRelativeLayout.java:44)
10-15 09:09:57.927 23530-23530/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.AbsListView.obtainView(AbsListView.java:2247)
at android.widget.ListView.makeAndAddView(ListView.java:1849)
at android.widget.ListView.fillDown(ListView.java:678)
at android.widget.ListView.fillFromTop(ListView.java:739)
at android.widget.ListView.layoutChildren(ListView.java:1664)
at android.widget.AbsListView.onLayout(AbsListView.java:2050)
at android.view.View.layout(View.java:14243)
at android.view.ViewGroup.layout(ViewGroup.java:4490)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
at com.app.name.widgets.SizeNotifierRelativeLayout.onLayout(SizeNotifierRelativeLayout.java:44)
at android.view.View.layout(View.java:14243)
at android.view.ViewGroup.layout(ViewGroup.java:4490)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14243)
at android.view.ViewGroup.layout(ViewGroup.java:4490)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
at android.view.View.layout(View.java:14243)
at android.view.ViewGroup.layout(ViewGroup.java:4490)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14243)
at android.view.ViewGroup.layout(ViewGroup.java:4490)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
at android.view.View.layout(View.java:14243)
at android.view.ViewGroup.layout(ViewGroup.java:4490)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14243)
at android.view.ViewGroup.layout(ViewGroup.java:4490)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2230)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1994)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1181)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4942)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
at android.view.Choreographer.doCallbacks(Choreographer.java:579)
at android.view.Choreographer.doFrame(Choreographer.java:548)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5370)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Orginal Question-> I have a statusbar get height function which is giving me a
FATAL EXCEPTION: main java.lang.ExceptionInInitializerError
The error is set of when MyActivity calls the
AndroidUtilities.statusBarHeight = getStatusBarHeight();
The function corresponding error:
at com.app.name.AndroidUtilities.(AndroidUtilities.java:31)
is
density = App.getInstance().getResources().getDisplayMetrics().density;
As I am relatively new to Android and Java, I would appreciate pointers as to what I am missing. Thanks!
MyActivity.java
package com.app.name;
import com.app.name.widgets.SizeNotifierRelativeLayout;
public class MyActivity extends ActionBarActivity implements ISideNavigationCallback, SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate, NotificationCenter.NotificationCenterDelegate {
private SizeNotifierRelativeLayout sizeNotifierRelativeLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
AndroidUtilities.statusBarHeight = getStatusBarHeight();
sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) findViewById(R.id.chat_layout);
sizeNotifierRelativeLayout.delegate = this;
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
}
/**
* Get the system status bar height
* #return
*/
public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
}
App.java
package com.app.name;
import android.app.Application;
import android.os.Handler;
public class App extends Application {
private static App Instance;
public static volatile Handler applicationHandler = null;
#Override
public void onCreate() {
super.onCreate();
Instance=this;
applicationHandler = new Handler(getInstance().getMainLooper());
NativeLoader.initNativeLibs(App.getInstance());
}
public static App getInstance()
{
return Instance;
}
}
AndroidUtilities.java
package com.app.name;
public class AndroidUtilities {
public static float density = 1;
public static int statusBarHeight = 0;
public static Point displaySize = new Point();
static {
density = App.getInstance().getResources().getDisplayMetrics().density;
checkDisplaySize();
}
}
logcat
10-15 07:57:41.119 15076-15076/? W/System.err? at com.app.name.MyActivity.onCreate(MyActivity.java:197)
10-15 07:57:41.130 15076-15076/? W/System.err? at com.app.name.AndroidUtilities.<clinit>(AndroidUtilities.java:31)
10-15 07:57:41.145 15076-15076/? E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.app.name.MyActivity.onCreate(MyActivity.java:197)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.access$600(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5370)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.app.name.AndroidUtilities.<clinit>(AndroidUtilities.java:31)
            at com.app.name.MyActivity.onCreate(MyActivity.java:197)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
            at android.app.ActivityThread.access$600(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5370)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

Android: Google play games services connection error ( java.lang.IllegalStateException: GoogleApiClient must be connected.)

I've programmed a game for android, everything works fine, but now I want my app to have Google play Games services (leaderboards and achievements). I used the Google example code to log in to the Google services (no errors in the script), but every time I want to connect with my App in debug mode, I get this error:
6-29 11:48:29.391 23779-23779/com.JFKGames.theepicbutton E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.JFKGames.theepicbutton, PID: 23779
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9001, result=10004, data=null} to activity {com.JFKGames.theepicbutton/com.JFKGames.theepicbutton.MainActivity}: java.lang.IllegalStateException: GoogleApiClient must be connected.
at android.app.ActivityThread.deliverResults(ActivityThread.java:3446)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3489)
at android.app.ActivityThread.access$1300(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: GoogleApiClient must be connected.
at com.google.android.gms.internal.fq.a(Unknown Source)
at com.google.android.gms.games.Games.c(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.submitScore(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.submitScore(Unknown Source)
at com.JFKGames.theepicbutton.MainActivity.onActivityResult(MainActivity.java:79)
at android.app.Activity.dispatchActivityResult(Activity.java:5446)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3442)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3489)
            at android.app.ActivityThread.access$1300(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5102)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
And the App crashes. Here's my code for the MainActivity where I want it to connect:
public class MainActivity extends BaseGameActivity implements
GameHelper.GameHelperListener, View.OnClickListener {
public static int REQUEST_LEADERBOARD = 1002;
boolean mExplicitSignOut = false;
boolean mInSignInFlow = false;
GoogleApiClient mClient() {
return null;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedClients(BaseGameActivity.CLIENT_GAMES | BaseGameActivity.CLIENT_APPSTATE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.startbutton);
button.setOnClickListener (this);
Button highscorebutton = (Button)findViewById(R.id.highscorebutton);
highscorebutton.setOnClickListener(this);
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
}
public void onClick(View view) {
if(view.getId()==R.id.startbutton) {
startActivityForResult(new Intent(this, buttonActivity.class), 1);
} else if(view.getId()==R.id.highscorebutton) {
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), getString(R.string.the_best_players)),REQUEST_LEADERBOARD);
} else if (view.getId() == R.id.sign_in_button) {
// start the asynchronous sign in flow
beginUserInitiatedSignIn();
}
else if (view.getId() == R.id.sign_out_button) {
// sign out.
signOut();
// show sign-in button, hide the sign-out button
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Games.Leaderboards.submitScore(getApiClient(), getString(R.string.the_best_players), resultCode);
if(requestCode==1) {
if(resultCode > leseHighscore()) {
schreibeHighscore(resultCode);
}
}
}
#Override
public void onSignInFailed() {
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
#Override
public void onSignInSucceeded() {
View a = findViewById(R.id.highscorebutton);
a.setVisibility(View.VISIBLE);
View b = findViewById(R.id.button3);
b.setVisibility(View.VISIBLE);
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}
}
Thanks, GoogleWelt
According to the official documentation, "Before any operation is executed, the GoogleApiClient must be connected"
When the user in not connected(signed in) and clicks to show leaderboards or achievements, it results in the exception thrown. Modify your code for launching the leaderboard like this:
} else if(view.getId()==R.id.highscorebutton) {
if (isSignedIn())
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), getString(R.string.the_best_players)), REQUEST_LEADERBOARD);
else showAlert("Please sign in to view leaderboards");
}
Use the same logic for showing achievements:
if (isSignedIn())
startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), REQUEST_ACHIEVEMENT);
else showAlert("Please sign in to view achievements");
Check the part where you are getting ApiClient i.e. getApiClient().
Write the code below to see if GoogleApiClient is Connected or not.
GoogleApiClient mGoogleApiClient;
if(mGoogleApiClient.isConnected()){
// good
}else{
//connect it
mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
}

Fatal Error On main Thread

I am receiving this fatal Error, when I try to access one particular function zipIt().
It doesn't matter from where I try to access it I always receive this error. This function simply zips a folder but program don't even go inside this function.
Logcat is displayed below:
Process: com.test.shahid, PID: 14839
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
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:1264)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1080)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5050)
            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:1264)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1080)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at java.io.File.fixSlashes(File.java:185)
at java.io.File.<init>(File.java:134)
at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
at com.test.shahid.MainActivity.zipIt(MainActivity.java:170)
at com.test.shahid.MainActivity.dispatchTakePictureIntent(MainActivity.java:490)
at com.test.shahid.MainActivity.onClickPhoto(MainActivity.java:468)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5050)
            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:1264)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1080)
            at dalvik.system.NativeStart.main(Native Method)
05-23 09:48:22.023 14839-14839/com.test.shahid I/Process﹕ Sending signal. PID: 14839 SIG: 9
Here is the function and variables associated with this function.
private static final File INPUT_FOLDER = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
private static final String ZIPPED_FOLDER = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).toString();
protected void zipIt(File inputFolder, String zipFilePath) {
try {
FileOutputStream fileOutputStream = new FileOutputStream(zipFilePath);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
String myname =inputFolder.toString();
ZipEntry folderZipEntry = new ZipEntry(myname);
zipOutputStream.putNextEntry(folderZipEntry);
File[] contents = inputFolder.listFiles();
for (File f : contents) {
if (f.isFile())
zipFile(f, zipOutputStream);
}
zipOutputStream.closeEntry();
zipOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
protected void zipFile(File inputFile, ZipOutputStream zipOutputStream) {
try { // A ZipEntry represents a file entry in the zip archive
// We name the ZipEntry after the original file's name
ZipEntry zipEntry = new ZipEntry(inputFile.getName());
zipOutputStream.putNextEntry(zipEntry);
FileInputStream fileInputStream = new FileInputStream(inputFile);
byte[] buf = new byte[1024];
int bytesRead;
// Read the input file by chucks of 1024 bytes
// and write the read bytes to the zip stream
while ((bytesRead = fileInputStream.read(buf)) > 0) {
zipOutputStream.write(buf, 0, bytesRead);
}
// close ZipEntry to store the stream to the file
zipOutputStream.closeEntry();
System.out.println("Regular file :" + inputFile.getCanonicalPath() + " is zipped to archive :" + ZIPPED_FOLDER);
} catch (IOException e) {
e.printStackTrace();
}
}
Well this is from where i am calling this function. I called this function just to check otherwise i have called this function from button and from several other functions. But nothing works.
public void onSync(View v) throws JSONException, IOException {
zipIt(INPUT_FOLDER, ZIPPED_FOLDER);
if (!isConnected()) {
AlertDialog.Builder mBuilder = new Builder(this);
mBuilder.setMessage("Please Enable Wifi to use this service");
mBuilder.setTitle("Enable WIFI");
mBuilder.setCancelable(false);
mBuilder.setPositiveButton("Settings",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent i = new Intent(
Settings.ACTION_WIFI_SETTINGS);
startActivity(i);
}
}
);
mBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// This code might cause problem so check when
// device is available
MainActivity.this.finish();
}
}
);
// create alert dialog
AlertDialog alertDialog = mBuilder.create();
// show it
alertDialog.show();
tvIsConnected.setText("You are NOT conncted");
// Intent myIntent = new
// Intent(Settings.ACTION_WIFI_SETTINGS);
// startActivity(myIntent);
return;
}
tvIsConnected.setBackgroundColor(0xFF00CC00);
tvIsConnected.setText("You are conncted");
handler.sendEmptyMessage(MSG_SYNC);
}
NullPointerException
Do you have "WriteExternalStorage" permision in your manifest?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Did you check the file path?
Environment.getExternalStorageDirectory() + "/some_foulder/file.txt"

Caused by java.lang.NullPointerException and java.lang.RuntimeException

I keep getting this error, I am not sure what's causing it. I declared and initialized the variables, but the error didn't disappear. I have been looking at the same error but I can't catch the mistake.
05-01 20:57:43.162 32675-32675/com.ammar.customlistview1.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40be21f8)
05-01 20:57:43.172 32675-32675/com.ammar.customlistview1.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ammar.customlistview1.app/com.ammar.customlistview1.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:976)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:1810)
at com.ammar.customlistview1.app.MainActivity.<init>(MainActivity.java:16)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1026)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
            at android.app.ActivityThread.access$600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:976)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
            at dalvik.system.NativeStart.main(Native Method)
Here is my class code:
package com.ammar.customlistview1.app;
/**
* Created by Ammar on 5/1/2014.
*/
public class person {
private String name = "Ammar";
private int age = 21;
private int picture = R.drawable.ic_launcher;
public person(String name, int age, int picture) {
this.name = name;
this.age = age;
this.picture = picture;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getPicture() {
return picture;
}
public void setPicture(int picture) {
this.picture = picture;
}
}
Here is my main activity code:
package com.ammar.customlistview1.app;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends Activity {
personadaptor adapter ;
ArrayList <person> theperson = new ArrayList<person>();
ListView lv = (ListView) findViewById(R.id.lvmain);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
person p1 = new person("Ammar", 21 , R.drawable.ic_launcher);
person p2 = new person("Ali", 25 , R.drawable.ic_launcher);
person p3 = new person("Saber", 23 , R.drawable.ic_launcher);
theperson.add(p1);
theperson.add(p2);
theperson.add(p3);
adapter = new personadaptor(theperson, this);
lv.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
You can't call findViewById() until you've called setContentView().
You cannot use Android UI methods such as findViewById() in the initializers of an Activity (or similar) Class, as these are only valid during and after the call to onCreate().
Move your initialization code to onCreate()
(And when you do so, be sure to put the findViewById() after setContentView() as Matiash so correctly points out - otherwise you will only get a different null pointer exception)
1.ListView lv;
Listview initialization shld be after
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lvmain);
2.no need to initialize this name,age and picture in person just write
private String name;
private int age ;
private int picture ;
3.in adapterclass u need layout
adapter = new personadaptor(theperson, this);//where is your row layout

Categories

Resources