1

Below i have pasted copy of my java,xml and logcat of the application.

Here goes my java code


package my.example.myproject;

import my.example.myproject.util.SystemUiHider;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 * 
 * @see SystemUiHider
 */
public class FullscreenActivity extends Activity {
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * If set, will toggle the system UI visibility upon interaction. Otherwise,
     * will show the system UI visibility upon interaction.
     */
    private static final boolean TOGGLE_ON_CLICK = true;

    /**
     * The flags to pass to {@link SystemUiHider#getInstance}.
     */
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

    /**
     * The instance of the {@link SystemUiHider} for this activity.
     */
    private SystemUiHider mSystemUiHider;
    Button iol,help,about;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);
        final View controlsView = findViewById(R.id.fullscreen_content_controls);
        iol = (Button)findViewById(R.id.iolCalculation);
        help = (Button)findViewById(R.id.sHelp);
        about = (Button)findViewById(R.id.sAbout);
        Thread iolthread=new Thread(){
            public void run(){
                try{
                    iol.setOnClickListener(new View.OnClickListener() {


                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                setContentView(R.layout.selection);
                            }
                    });
                    Intent iolIntent=new Intent(FullscreenActivity.this,Selection.class);
                    startActivity(iolIntent);
                }
                finally{
                    finish();
                }
            }
        };  
        iolthread.start();
        // Set up an instance of SystemUiHider to control the system UI for
        // this activity.
        mSystemUiHider = SystemUiHider.getInstance(this, controlsView,
                HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                    // Cached values.
                    int mControlsHeight;
                    int mShortAnimTime;

                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                            // If the ViewPropertyAnimator API is available
                            // (Honeycomb MR2 and later), use it to animate the
                            // in-layout UI controls at the bottom of the
                            // screen.
                            if (mControlsHeight == 0) {
                                mControlsHeight = controlsView.getHeight();
                            }
                            if (mShortAnimTime == 0) {
                                mShortAnimTime = getResources().getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView
                                    .animate()
                                    .translationY(visible ? 0 : mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        } else {
                            // If the ViewPropertyAnimator APIs aren't
                            // available, simply show or hide the in-layout UI
                            // controls.
                            controlsView.setVisibility(visible ? View.VISIBLE
                                    : View.GONE);
                        }

                        if (visible && AUTO_HIDE) {
                            // Schedule a hide().
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });

        // Set up the user interaction to manually show or hide the system UI.
        controlsView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TOGGLE_ON_CLICK) {
                    mSystemUiHider.toggle();
                } else {
                    mSystemUiHider.show();
                }
            }
        });

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.

    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        // Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);
    }

    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    /**
     * Schedules a call to hide() in [delay] milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

XML

<FrameLayout 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:background="@color/black"
    tools:context=".FullscreenActivity" 
    android:id="@+id/frame_layout">

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?buttonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="horizontal"
            tools:ignore="UselessParent" >
        </LinearLayout>

        <Button
            style="@style/ButtonBarButton"
            android:layout_width="222dp"
            android:layout_height="62dp"
            android:layout_marginLeft="45dp"
            android:layout_marginTop="75dp"
            android:background="@color/black"
            android:paddingLeft="20dp"
            android:id="@+id/iolCalculation"
            android:text="@string/Button"
            android:textColor="@color/WhiteSmoke"
            android:textStyle="bold" />

        <Button
            style="@style/ButtonBarButton"
            android:layout_width="222dp"
            android:layout_height="62dp"
            android:layout_marginLeft="45dp"
            android:id="@+id/sHelp"
            android:layout_marginTop="139dp"
            android:background="@color/Black"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:text="@string/Button1"
            android:textColor="@color/WhiteSmoke"
            android:textStyle="bold" />

        <Button
            style="@style/ButtonBarButton"
            android:layout_width="222dp"
            android:layout_height="62dp"
            android:id="@+id/sAbout"
            android:layout_marginLeft="45dp"
            android:layout_marginTop="203dp"
            android:background="@color/Black"
            android:paddingLeft="10dp"
            android:text="@string/Button2"
            android:textColor="@color/WhiteSmoke"
            android:textStyle="bold" >

        </Button>
</FrameLayout>

logcat

12-16 10:48:26.975: E/Trace(767): error opening trace file: No such file or directory (2)
12-16 10:51:38.199: E/AndroidRuntime(767): FATAL EXCEPTION: main
12-16 10:51:38.199: E/AndroidRuntime(767): java.lang.NullPointerException
12-16 10:51:38.199: E/AndroidRuntime(767):  at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:168)
12-16 10:51:38.199: E/AndroidRuntime(767):  at android.view.View.performClick(View.java:4202)
12-16 10:51:38.199: E/AndroidRuntime(767):  at android.view.View$PerformClick.run(View.java:17340)
12-16 10:51:38.199: E/AndroidRuntime(767):  at android.os.Handler.handleCallback(Handler.java:725)
12-16 10:51:38.199: E/AndroidRuntime(767):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-16 10:51:38.199: E/AndroidRuntime(767):  at android.os.Looper.loop(Looper.java:137)
12-16 10:51:38.199: E/AndroidRuntime(767):  at android.app.ActivityThread.main(ActivityThread.java:5039)
12-16 10:51:38.199: E/AndroidRuntime(767):  at java.lang.reflect.Method.invokeNative(Native Method)
12-16 10:51:38.199: E/AndroidRuntime(767):  at java.lang.reflect.Method.invoke(Method.java:511)
12-16 10:51:38.199: E/AndroidRuntime(767):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-16 10:51:38.199: E/AndroidRuntime(767):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-16 10:51:38.199: E/AndroidRuntime(767):  at dalvik.system.NativeStart.main(Native Method)

i have tried every possible solution in stackoverflow but in vain.help me. I think mostly there is a problem in xml to java display content.Also do i need to put in id for every layout in xml and how does the java code detect the layout to be displayed

here goes my selection java code and xml

    package com.example.iolcalci;

import android.app.Activity;
import android.os.Bundle;

public class Selection extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.selective);

    }

}

<?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="match_parent"
    android:background="@color/black"
    android:orientation="vertical" >

    <Spinner
        android:id="@+id/formulae"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:background="@color/LightSkyBlue"
        android:prompt="@string/prompt"
        android:entries="@array/formulas" />

    <TextView
        android:id="@+id/k2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/k1"
        android:layout_below="@+id/k1"
        android:layout_marginTop="38dp"
        android:text="@string/K2"
        android:textColor="@color/White"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/al_const"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/al"
        android:layout_below="@+id/al"
        android:layout_marginTop="44dp"
        android:text="@string/Rx"
        android:textColor="@color/White"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/al"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/k2"
        android:layout_below="@+id/k2"
        android:layout_marginTop="38dp"
        android:text="@string/AL"
        android:textColor="@color/White"
        android:textSize="25sp" />

    <EditText
        android:id="@+id/k2_editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/al"
        android:layout_alignRight="@+id/al_editText"
        android:layout_alignTop="@+id/k2"
        android:layout_marginLeft="120dp"
        android:background="@color/black"
        android:ems="10"
        android:inputType="numberDecimal"
        android:textColorLink="@color/white" />

    <EditText
        android:id="@+id/al_editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/formulae"
        android:layout_alignTop="@+id/al"
        android:layout_marginLeft="120dp"
        android:ems="10"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/al_const_editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/al_const"
        android:layout_alignRight="@+id/al_editText"
        android:layout_marginLeft="120dp"
        android:ems="10"
        android:inputType="numberDecimal" />

    <Button
        android:id="@+id/result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@color/LightSkyBlue"
        android:text="@string/Result" />

    <EditText
        android:id="@+id/k1_editText"
        android:layout_width="wrap_content"
        android:layout_height="37dp"
        android:layout_alignLeft="@+id/k2_editText"
        android:layout_alignRight="@+id/formulae"
        android:layout_below="@+id/formulae"
        android:layout_marginTop="30dp"
        android:background="@color/black"
        android:ems="10"
        android:inputType="numberDecimal"
        android:textColorLink="@color/White" />

    <TextView
        android:id="@+id/k1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/k1_editText"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="27dp"
        android:text="@string/K1"
        android:textColor="@color/white"
        android:textSize="25sp" />

</RelativeLayout>

THE NEW LOGCAT


   12-21 10:44:50.419: W/Trace(766): Unexpected value from nativeGetEnabledTags: 0
12-21 10:44:50.573: W/Trace(766): Unexpected value from nativeGetEnabledTags: 0
12-21 10:44:50.573: W/Trace(766): Unexpected value from nativeGetEnabledTags: 0
12-21 10:44:50.923: D/AndroidRuntime(766): Shutting down VM
12-21 10:44:50.923: W/dalvikvm(766): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-21 10:44:50.933: E/AndroidRuntime(766): FATAL EXCEPTION: main
12-21 10:44:50.933: E/AndroidRuntime(766): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.MainActivity}: java.lang.NullPointerException
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.os.Looper.loop(Looper.java:137)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.ActivityThread.main(ActivityThread.java:5039)
12-21 10:44:50.933: E/AndroidRuntime(766):  at java.lang.reflect.Method.invokeNative(Native Method)
12-21 10:44:50.933: E/AndroidRuntime(766):  at java.lang.reflect.Method.invoke(Method.java:511)
12-21 10:44:50.933: E/AndroidRuntime(766):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-21 10:44:50.933: E/AndroidRuntime(766):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-21 10:44:50.933: E/AndroidRuntime(766):  at dalvik.system.NativeStart.main(Native Method)
12-21 10:44:50.933: E/AndroidRuntime(766): Caused by: java.lang.NullPointerException
12-21 10:44:50.933: E/AndroidRuntime(766):  at com.example.iolcalci.MainActivity.onCreate(MainActivity.java:23)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.Activity.performCreate(Activity.java:5104)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-21 10:44:50.933: E/AndroidRuntime(766):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-21 10:44:50.933: E/AndroidRuntime(766):  ... 11 more

Manifest file

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.iolcalci"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.iolcalci.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="Selection"
            android:exported="false"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name">
                <intent-filter>
                <action android:name="com.example.iolcalci.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
        </activity>
    </application>

</manifest>
human
  • 637
  • 4
  • 15
  • 41
  • What would be the reason for using the `iolthread` `Thread` to set the `OnClickListener`? – user Dec 16 '12 at 12:12
  • @Luksprog i am a beginner in android and can u please suggest me me alternate statement – human Dec 16 '12 at 12:14

1 Answers1

1

Judging from your code I'm going to go with the conjecture that this line is causing the error:

setContentView(R.id.selection);

There's no need to change the contentView of the activity from which you're calling the "selection" activity. You should read up on intents. I'm assuming that when the button is clicked, you want the new activity and it's content to pop up. For that, do this :

try{
                iol.setOnClickListener(new View.OnClickListener() {


                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                           Intent iolIntent=new Intent(FullscreenActivity.this,Selection.class);
                startActivity(iolIntent);
                        }
                });
            }

Also set your button's layout width and layout height to "wrap_content". Definite measurements won't work well because there are many resolutions possible.

android:layout_height="wrap_content"
android:layout_width="wrap_content"

In case of more errors, post the new logcat, please.

I found this in your selection.java:

setContentView(R.layout.selective);

This means you should have a selective.xml file in your res/layout/ folder.

This selective.xml file should contain a definition of EditText. Example,

<EditText
    android:id="@+id/k1_editText"
    android:layout_width="wrap_content"
    android:layout_height="37dp"
    android:layout_alignLeft="@+id/k2_editText"
    android:layout_alignRight="@+id/formulae"
    android:layout_below="@+id/formulae"
    android:layout_marginTop="30dp"
    android:background="@color/black"
    android:ems="10"
    android:inputType="numberDecimal"
    android:textColorLink="@color/White" />

You need to reference this in the activity file with this piece of code:

EditText ed=new EditText findViewById(R.id.k2_editText);

Now the EditText field will be displayed.

If you want to make your EditText object global, declare it in the class and then initialize it after setting content view. Like this,

public class Selection extends Activity {
EditText ed;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.selective);
    EditText ed=new EditText findViewById(R.id.k2_editText);
}

Make sure you always initialize a widget object AFTER the creation of the activity and setting content view, because otherwise the compiler is going to have to initialize something which hasn't been referenced yet. The layout file is referenced only after setting content view. Only after setting the layout file can you initialize objects to whatever is present inside the layout file.

If you like the answer, do vote it up.

Karthik Balakrishnan
  • 4,353
  • 6
  • 37
  • 69
  • but i want a custom made button rather wrap content. and i have also added selection.java and xml code. help me – human Dec 21 '12 at 10:38
  • yup. can you help me with the manifest file. i think there is a problem in manifest file. updated manifest file in question – human Dec 22 '12 at 06:26
  • Your manifest seems fine. What does your app do? Does it use any features for which permissions have to be requested? – Karthik Balakrishnan Dec 22 '12 at 12:52
  • The app should work fine if you changed what I said. Remove all the old code and logcats and post your new code and logcat, please. – Karthik Balakrishnan Dec 23 '12 at 05:14
  • what should i put in selection class? – human Dec 23 '12 at 11:19
  • and should i create a new thread in the mainactivity class before try block – human Dec 23 '12 at 11:22
  • What you put in the selection class doesn't matter right now, it should execute fine. Please do what I said, remove the old stuff and put the new code and logcat. – Karthik Balakrishnan Dec 23 '12 at 11:41
  • yes bro i got the 2nd screen. but its just displaying blank.how to display the spinner textview and edittext fields in 2nd screen. – human Dec 24 '12 at 07:37
  • logcat error has one line 12-24 07:35:44.757: E/Trace(768): error opening trace file: No such file or directory (2) – human Dec 24 '12 at 07:38