Short update: 1 - found the mistake that it didn't show I accidentally
didn't place any of the ViewStubs within the RelativeLayout of the
SlidingDrawer, so it was never part of the content...really stupid mistake
:)

On Sun, Aug 1, 2010 at 4:49 PM, Kostya Vasilyev <[email protected]> wrote:

>  Aha, now we're on to something.
>
> 1 - I think it does, but the inflated content is such that you don't see
> it. Try playing with the inflated layout's background color, and with
> ViewStub's width and height (maybe set to fixed values for debugging, like
> both 200dp).
>
> 2 - Inflating a ViewStub removes the stub, and replaces it with the
> inflated content. So the second time through the ViewStub isn't there
> anymore, and the code crashes since the return value of
> findViewById(R.id.stub_exposure) is null.
>
> You need to be able to tell apart the first and second time through this
> code. I see you are saving the inflated layout in "importStub", maybe check
> it for null, and if it's not null, then the view is already inflated. Or
> check the return value of findViewById(R.id.stub_exposure).
>
> "@+id/NO_ID" does not have any special meaning, it's just an id, you'd
> refer to it as "R.id.NO_ID". It certainly doesn't change the behavior of
> ViewStub.inflate().
>
> -- Kostya
>
> 01.08.2010 19:30, Victoria Busse пишет:
>
> Yes, I know that my try catch was wrong, but I corrected it eventually...
>
>  I think you are right the error is always displayed when I press the
> button a second time...but that brings me to two new problems or questions:
>
>  1. Why doesn't the inflated View or layout show up?
>
>  2. How can I allow the button to be clicked several times and every time
> calling the ViewStub and its inflated layout. (I already changed inflatedId
> to NO_ID, but apparently that doesn't do the trick)
>
>  <ViewStub
>      android:id="@+id/stub_exposure"
>      android:inflatedId="@+id/NO_ID"
>
>      android:layout="@layout/exposureview"
>
>      android:layout_width="fill_parent"
>      android:layout_height="wrap_content"
>      android:background="#77000000">
>      </ViewStub>
>
>
>
>
> On Sun, Aug 1, 2010 at 4:07 PM, Kostya Vasilyev <[email protected]>wrote:
>
>> Victoria,
>>
>> Has the ViewStub already been inflated by any chance? That is, maybe this
>> is the second time through you're clicking the button?
>>
>> If so, you should know that inflating a ViewStub removes it from the
>> hierarchy and replaces it with the layout you provide with android:layout,
>> giving it the id set by android:inflatedId.
>>
>> Also, your try/catch block is wrong, it should be inside the onClick
>> listener - think about it, the exception happens when you click the button,
>> not when you set the onClick handler.
>>
>>
>> btnExposure.setOnClickListener(new OnClickListener()
>>         {
>>          @Override
>> public void onClick(View v) {
>>  *try {*
>>           ViewStub stub = (ViewStub) findViewById(R.id.stub_exposure);
>>          importStub = stub.inflate();
>>  *}catch (Exception e){
>>                 // pass "e" to Log.e to see full stack trace in logcat
>> *
>> *         Log.e("ERROR", "Error in Code:" +e.toString(), e);*
>> *} *
>>  }
>>          });
>>
>> You also need to modify the layout to be inflated -the way it is now, both
>> views are on top of one another. This is the fix:
>>
>> <TextView
>>     android:id="@+id/text_view"
>>
>> <SeekBar
>>     android:layout_below="@id/text_view
>>
>> And last but not least, I think this is the actual error:
>>
>> android:text="@+String/hello"
>>
>> There is no "+" notation for strings, and it's "string" not "String"
>> anyway. You can do either
>>
>> android:text="@string/hello"
>>
>> or
>>
>> android:text="Hello"
>>
>> -- Kostya
>>
>> 01.08.2010 16:27, Victoria Busse пишет:
>>
>> Okay I got the "Source" of the error: the try and catch returned  that the
>> Null Pointer Exception derives from this part as you already suspected:
>>
>>  ViewStub stub = (ViewStub) findViewById(R.id.stub_exposure);
>>           importStub = stub.inflate();
>>  But I don't understand why it should be null as I followed the examples
>> I found on the web... e.g. this here:
>> http://developer.android.com/reference/android/view/ViewStub.html
>>
>>  And this is the code in the xml, in which I call the ViewStub:
>>
>>    <ViewStub
>>      android:id="@+id/stub_exposure"
>>      android:inflatedId="@+id/stub_exposure_view"
>>
>>      android:layout="@layout/exposureview"
>>
>>      android:layout_width="fill_parent"
>>      android:layout_height="wrap_content"
>>      android:background="#77000000">
>>      </ViewStub>
>>
>>  And here is the according layout xml for the inflated View, the
>> exposureview.xml:
>>
>>  <?xml version="1.0" encoding="utf-8"?>
>> <RelativeLayout  xmlns:android="
>> http://schemas.android.com/apk/res/android";
>>  android:layout_width="fill_parent"
>>  android:layout_height="fill_parent"
>>  >
>>  <TextView
>>  android:layout_width="wrap_content"
>>  android:layout_height="wrap_content"
>>  android:text="@+String/hello"
>>  ></TextView>
>>  <SeekBar
>>  android:layout_width="wrap_content"
>>  android:layout_height="wrap_content"
>>  android:thumb="@drawable/seek_thumb"
>>  android:progress="50"
>>  android:max="100">
>>  </SeekBar>
>>
>>  </RelativeLayout>
>>
>>
>>
>> 2010/8/1 Victoria Busse <[email protected]>
>>
>>> mhmmm, I tried
>>>
>>>  try{
>>>          btnExposure.setOnClickListener(new OnClickListener()
>>>         {
>>>
>>>          @Override
>>>  public void onClick(View v) {
>>>
>>>           ViewStub stub = (ViewStub) findViewById(R.id.stub_exposure);
>>>          importStub = stub.inflate();
>>>
>>>  }
>>>          });}catch (Exception e){
>>>          Log.e("ERROR", "Error in Code:" +e.toString());
>>>         }
>>>
>>>  but I don't get any output at all...
>>>
>>> 2010/8/1 Kostya Vasilyev <[email protected]>
>>>
>>>> Victoria,
>>>>
>>>> Judging by logcat, it looks like "stub" variable, the result of calling
>>>> findViewById(R.id.stub_exposure) is null. You should check this in the
>>>> debugger.
>>>>
>>>> -- Kostya
>>>>
>>>> 01.08.2010 13:46, Victoria Busse пишет:
>>>>
>>>> Okay found the problem, I simply forgot to define the button's
>>>> View  btnExposure = (ImageButton) findViewById(R.id.button_exposure);
>>>> So this - quite simple - problem's solved, but now I got at new
>>>> NullPointerException at
>>>> com.mobilevideoeditor.moved.EditorView$1.onClick(EditorView.java:54), which
>>>> is importStub = ((ViewStub) findViewById(R.id.stub_exposure)).inflate();
>>>>  And this is what I don't really understand because I am not familiar
>>>> with ViewStubs yet...
>>>>
>>>>  I also tried ViewStub stub = (ViewStub)
>>>> findViewById(R.id.stub_exposure);
>>>>          importStub = stub.inflate();
>>>> but again I get the Null Pointer Exception at importStub =
>>>> stub.inflate();
>>>>
>>>>  Could there be s.th wrong with the exposureview.xml that I use to
>>>> inflate the stub??
>>>>
>>>>
>>>> 2010/8/1 Victoria Busse <[email protected]>
>>>>
>>>>> Here is the Logcat:
>>>>>
>>>>>  08-01 08:17:11.984: ERROR/AndroidRuntime(223): Uncaught handler:
>>>>> thread main exiting due to uncaught exception
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):
>>>>> java.lang.RuntimeException: Unable to start activity
>>>>> ComponentInfo{com.mobilevideoeditor.moved/com.mobilevideoeditor.moved.EditorView}:
>>>>> java.lang.NullPointerException
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.app.ActivityThread.access$2200(ActivityThread.java:119)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.os.Handler.dispatchMessage(Handler.java:99)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.os.Looper.loop(Looper.java:123)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.app.ActivityThread.main(ActivityThread.java:4363)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> java.lang.reflect.Method.invokeNative(Native Method)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> java.lang.reflect.Method.invoke(Method.java:521)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> dalvik.system.NativeStart.main(Native Method)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223): Caused by:
>>>>> java.lang.NullPointerException
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> com.mobilevideoeditor.moved.EditorView.onCreate(EditorView.java:49)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     at
>>>>> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
>>>>> 08-01 08:17:11.994: ERROR/AndroidRuntime(223):     ... 11 more
>>>>>
>>>>>
>>>>>  The Null pointer exception apparently is at
>>>>> com.mobilevideoeditor.moved.EditorView.onCreate(EditorView.java:49), which
>>>>> is the Image Button onClickListener
>>>>>
>>>>>
>>>>>
>>>>> 2010/8/1 Kostya Vasilyev <[email protected]>
>>>>>
>>>>>  Logcat?
>>>>>>
>>>>>> --
>>>>>> Kostya Vasilyev -- http://kmansoft.wordpress.com
>>>>>>
>>>>>> 01.08.2010 12:32 пользователь "Victoria Busse" <
>>>>>> [email protected]> написал:
>>>>>>
>>>>>>
>>>>>> Update, just found a mistake within the ViewStub declaration as I
>>>>>> forgot to specify a layout, here is the updated code because the error is
>>>>>> still there :(( If someone knows what I am doing wrong please help me
>>>>>> because after finding out that I forgot the layout *I thought it
>>>>>> would work *but apparently it still doesn't
>>>>>>
>>>>>>  <ViewStub
>>>>>>        android:id="@+id/stub_exposure"
>>>>>>        android:inflatedId="@+id/stub_exposure_view"
>>>>>>
>>>>>>         android:layout="@layout/exposureview"
>>>>>>
>>>>>>
>>>>>>        android:layout_width="fill_parent"
>>>>>>        android:layout_height="fill_parent"
>>>>>>         androi...
>>>>>>
>>>>>> On Sun, Aug 1, 2010 at 1:11 AM, kivy <[email protected]>
>>>>>> wrote:
>>>>>> >
>>>>>> > Hi there,
>>>>>> >
>>>>>>  > I just ...
>>>>>>
>>>>>> --
>>>>>>  You received this message because you are subscribed to the Google
>>>>>>  Groups "Android Developers" g...
>>>>>>
>>>>>> --
>>>>>>  You received this message because you are subscribed to the Google
>>>>>> Groups "Android Developers" group.
>>>>>> To post to this group, send email to
>>>>>> [email protected]
>>>>>> To unsubscribe from this group, send email to
>>>>>> [email protected]<android-developers%[email protected]>
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/android-developers?hl=en
>>>>>>
>>>>>
>>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to
>>>> [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/android-developers?hl=en
>>>>
>>>>
>>>>
>>>>   --
>>>> Kostya Vasilev -- WiFi Manager + pretty widget -- 
>>>> http://kmansoft.wordpress.com
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to
>>>> [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<android-developers%[email protected]>
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/android-developers?hl=en
>>>>
>>>
>>>
>>   --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>>
>>
>> --
>> Kostya Vasilev -- WiFi Manager + pretty widget -- 
>> http://kmansoft.wordpress.com
>>
>>    --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<android-developers%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
>
>
> --
> Kostya Vasilev -- WiFi Manager + pretty widget -- 
> http://kmansoft.wordpress.com
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to