Mohammed Azeem

Ranch Hand
+ Follow
since Aug 17, 2012
Cows and Likes
Cows
Total received
3
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
1
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mohammed Azeem

Good Morning Ron,

OK so, LogCat reveals the following pertinent lines:

01-23 03:19:29.331 7860-7860/com.example.hour2appversion2 E/AndroidRuntime: FATAL EXCEPTION: main

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
       at com.example.hour2appversion2.ActivityC.onClickSend(ActivityC.java:24)
       at java.lang.reflect.Method.invoke(Native Method)



It seems there is NullPointerException:

  *   Line 14 in the code listed in the post (but line 24 in the actual code) the the EditText object "e" is set to null

But how can this be, since I have declared e has an EditText object and assigned it in line 9 of Class ActivityC ?

It is 3.30 am in England so I will act on any replies tomorrow. Thanks.
3 days ago
Hello, good evening.

I am exploring startActivityForResult. I am using a self-study book.

*  MainActivity starts ActivityC for a result. The method onClickGetData accomplishes this.
*  ActivityC returns the text typed into an EditText. The method onClickSendData does this.
*  MainActivity receives the data and displays it in a TextView.

However, when I tap "Send Data" in ActivityC the app crashes ("Unfortunately app has stopped working").

I am using Android Studio. In the original code from the self-study book everything is inside the onCreate method and uses inner classes to implement the button handlers.

My button handlers are outside the onCreate method so I've had to declare the TextView and EditView variables as class variables because they are used in multiple methods. I'm wondering whether these changes are causing the app to crash.

Any insights most welcome.




and class ActivityC is:

4 days ago
Good Afternoon.

I am proficient in Java and now studying the basics of Android App Development.

I want to re-use the layout activity_main.xm  for a second activity to avoid the laborious work of having to re-create it in the layout editor.
In other words I want to sub-class the Activity ActivityMain but also "sub-class" its layout.

Any suggestion ?

I have searched and searched the web without success.

Thanks,
Mohammed.
2 weeks ago
No I'm sorry it is not solved

The info I found does not answer my query.

Any suggestions most welcome.

Mohammed.
2 weeks ago
Solved. Answer in official android tutorials.

If you already have a layout and want to create an alternative version to optimize the layout for different screen sizes or orientations, follow these steps:
1. Open your original layout file and be sure you're viewing the design editor (click the Design tab at the bottom of the window).
2. Click Orientation for Preview   in the toolbar. In the dropdown list, either click a suggested variant such as Create Landscape Variant and you're done, or click Create Other and continue to the next step.
3. In the dialog that appears, you simply need to define the resource qualifiers for the directory name. You can type it in Directory name or select from the Available qualifiers list, one at a time, and click Add  .
4. Once you've added all your qualifiers, click OK.
When you have multiple variations of the same layout, you can easily switch between them from the list that appears when you click Layout Variants  .



2 weeks ago
Solved. The answer is in the official android tutorials:

If you already have a layout and want to create an alternative version to optimize the layout for different screen sizes or orientations, follow these steps:
1. Open your original layout file and be sure you're viewing the design editor (click the Design tab at the bottom of the window).
2. Click Orientation for Preview   in the toolbar. In the dropdown list, either click a suggested variant such as Create Landscape Variant and you're done, or click Create Other and continue to the next step.
3. In the dialog that appears, you simply need to define the resource qualifiers for the directory name. You can type it in Directory name or select from the Available qualifiers list, one at a time, and click Add  .
4. Once you've added all your qualifiers, click OK.
When you have multiple variations of the same layout, you can easily switch between them from the list that appears when you click Layout Variants  .



2 weeks ago
Good Afternoon.

I am proficient in Java and now studying the basics of Android App Development.

I want to re-use the layout activity_main.xm  for a second activity to avoid the laborious work of having to re-create it in the layout editor.
In other words I want to sub-class the Activity ActivityMain but also "sub-class" its layout.

Any suggestion ?

I have searched and searched the web without success.

Thanks,
Mohammed.
2 weeks ago
Good Afternoon,

I am proficient in Java and now I am studying basics of Android Development in Android Studio.

I want to re-use the layout activity_main.xml in another activity to save the laborious work of re-creating it in the layout editor.
In other words I want to sub-class MainActivity but also "sub-class" its layout.

Any suggestion ?

I have searched, and searched the web for an answer without success.

Thanks
Mohammed.
2 weeks ago
Thank you Tim, you must have posted just as I was typing.
2 weeks ago
Hello again,

I vaguely recall hash numbers and I think there is a similarity between them and key-value pairs.

I've also watched a few youtube videos and this is my (imperfect) understanding:

* keys map a single label to a collection of related values (e.g bank account (label) to account name, balance etc)
* therefore the key must be unique
* so the key must not change - it must be declared as a final string.

I have tested my hypothesis as follows:

* I have assigned EXTRA_MESSAGE any old literal - the app still works
* I have declared EXTRA_MESSAGE but left it unassigned - the app still works as it should.
* Ihave declared EXTRA_MESSAGE as non-final - and the code still works (though I appreciated why it should be final).

2 weeks ago
Good Morning,

I am fairly proficient in Java and now I would like to put it to the test by exploring Android Application Development.

My questions are, in the listing below (taken from the official online android tutorials):

* Why is the key EXTRA_MESSAGE defined as a final string ?
* And is there any significance in literal value "com.example.myfirstapp.MESSAGE" ?  Would any literal do? (I will test this)
*

Thanks for any replies.

2 weeks ago
Hello,

I get slightly obsessed with little details which are often  beyond the scope of my immediate study purposes but I can't move on until they're resolved. I don't know whether this is a good or bad thing.

Anyway,

Suppose str1 refers to one String object and str2 refers to another, and I want to compare these for equaility.

The equals() method of str1 object essentially compares its own private final value with that that of the second string. How does it again access to the other sting object's private final value ?

Thanks for any responses.

Mohammed.
9 months ago
OK, thanks Campbell.

I extend classes willy-nilly.

So is it good practice to provide a no-parameter constructor in my own classes in case I or others wish to extend it, or is it up to users to look at the documentation to see which constructors are available ?
1 year ago
Good Evening,

I've been playing around constructors and inheritance.

I know that constructors are not inherited but those of a base class can be referred to by 'super'.

So what happens when, the derived class has no user-defined constructor but the base class does ?


In the following code:
  *   class A extends B.
  *   A is given a user-defined constructor; B is not.  So the compile ought to provide it with the construtor:
        equivalent to:
       

  *  The code fails unless line 21 is uncommented

All insights greatly appreciated,

Mohammed.



1 year ago