Issue with displaying TabHost Layout in new Intent - android

I am having an issue with using TabHost in a new Intent of type TabActivity which I hope you can point me in the right direction. Funnily it works fine when I try to view it in the original Intent : setContentView(R.layout.main)
I get a "forced closed" and within logcat, I get the following error even though my Tabhost id = "#android:id/tabhost":
02-18 22:23:11.937:
ERROR/AndroidRuntime(5944): Caused by:
java.lang.RuntimeException: Your
content must have a TabHost whose id
attribute is 'android.R.id.tabhost'
I have declared the second intent in the Manifest.xml file:
XML:
<activity android:name=".NextActivity" android:label="#string/app_name" >
Within the first activity (MainActivity), I start the second intent (NextActivity), with extras, as follows:
Intent nextActivity = new Intent(MainActivity.this,NextActivity.class);
Bundle b_next=new Bundle();
b_next.putString("s_string", myString);
nextActivity.putExtras(b_next);
In my NextActivity.java file, I get the extras and try to display the TabHost View:
public class NextActivity extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String myString;
Bundle b_initial;
b_initial = getIntent().getExtras();
myString = b_initial.getString("s_string");
setContentView(R.layout.main);
}
}
I get the same error with using the TabHost example on the Android Developer site (Hellow View):
Main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
Thanks in advance folks...
CLARIFICATION:
This is what I really get from LogCat:
java.lang.NullPointerException
at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java 285)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)
at android.view.ViewRoot.handleMessage(ViewRoot.java 1645)
at android.os.Handler.dispatchMessage(Handler.java 99)
at android.os.Looper.loop(Looper.java 123)
at android.app.ActivityThread.main(ActivityThread.java 3948)
at java.lang.reflect.Method.invokeNative(Native
Method)
at java.lang.reflect.Method.invoke(Method.java 521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java 782)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java 540)
at dalvik.system.NativeStart.main(Native
Method)

I had the same problem. Luckily there was a quick fix:
Delete the R file.
Wait for your IDE to generate the file.
Profit!

I had copied and pasted code and noticed that in the id attribute I had:
android:id="#+id/tabs"
when what I really wanted was:
android:id="#android:id/tabs"

I have previously constructed tabhosts with an id of android:id="#+id/tabhost". Does this work for you?
You could also consider constructing your tab view programmatically:
TabHost t = getTabHost();
TabSpec tab = t.newTabSpec(label)
.setIndicator(label, icon)
.setContent(intent);
t.addTab(tab);

I also encountered this problem. I had an XML file that wasn't linked against my code properly in my res/layout. When I fixed the naming, the problem went away.

even though i had changed my main.xml to use android:id="#android:id/tabhost" like the error stated, it kept trying to use the old name. finally i found the file res/layout-port/main.xml that was identical to main.xml except used the wrong android:id. i must have added a portrait view accidentally and it was holding on to the old value. either fixing the portrait file or removing it fixes my problem.

I also had this error. For me it would appear after obfuscation(via ProGuard), pre obfuscation it was fine.
In the end I renamed my layout file to something more complex and unique, and ProGuard didn't mess up the linking. Bit easer than going down the ProGuard configeration path.
So my issue was similar to SapphireSun, though expressed via a different process(and post eclipse, just to make things that bit more difficult).
This is perhaps one of the more obscure ways to get this error, but I thought it worth a mention.

"public class NextActivity extends TabActivity" --change TabActivity to ActivityGroup.
when problem happen when you want wo run tabhost in tabhost.it is ok.

I am experiencing the same error in a team-project, when using SVN. Sometimes, eclipse uploads classes.dex and resources.ap_ from the bin folder of the project and others get it via SVN update.
Since these binary files are generated on the individual machines with individual code, thats probably where the error comes from.
Cleaning the project files (Project -> Clean) always solved the issue for us!

I had this issue along with 'ERROR: Unknown option '--no-crunch''. If you updated ADT plug-in in Eclipse but have not updated the SDK at the same time. Updating the SDK Manager in Eclipse, fixed the issue for me.

Related

Admob 6.1.0 for monodroid

I have an app made with monodroid, it's on release stage (ready to get released) but I would like to have a free ad-supported version of my app. I've been searching the web for a tutorial of Admob 6.1.0 implementation on monodroid without any luck. I'd have to mention that I've never worked with ads before.
I was wondering if anyone has been able to use Admob 6.1.0 on monodroid and if you could share your knowledge
I've seen this source code and also this tutorial, but I just can't manage to understand correctly how to implement it. I't would be nice if someone could make an answer as a community wiki so it can help others to get introduced to Admob in monodroid
EDIT:
Tried Greg Shackles sample step by step, i'm now getting this error android.view.InflateException: Binary XML file line #1: Error inflating class com.google.ads.AdView. Any sugestion of how to make it work?
EDIT 2:
Changed the XML file and now getting 2 new errors: Java.Lang.NoClassDefFoundError and System.TypeInitializationException. XML looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/Background2"
>
<com.google.ads.AdView android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="AD_UNIT_ID_GOES_HERE"
ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
And adview is called like this:
public class MyActivity : Activity
{
private View _adView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.AboutActivityLayout);
AdMobHelper.RegisterEmulatorAsTestDevice();
_adView = FindViewById(Resource.Id.Ad);
AdMobHelper.RequestFreshAd(_adView);
loadData();
}
}
The first error you got "android.view.InflateException: Binary XML file line #1: Error inflating class com.google.ads.AdView" is related to the Jar Build Action setting.
You should check two things first:
the jar file has the Build Action property set to "AndroidJavaLibrary"
the java file called "AdMobHelper.java" should have the Build Action property set to "AndroidJavaSource"
It seems to me that the error you are getting now is related to the java file not being correctly configured as an AndroidJavaSource.

Android XML Error - First App - NetBeans

I've just started this evening into developing my first Android app and have come across an error that for the life of me I can't see where is coming from
When i launch my test app in the emulator it force closes with the error "The application Test App (psrocess Test.App) has stopped unexpectedly. Please try again."
So far I've checked: The Android Development output - nothing untoward,launches fine and locates activity and intent
The Emulator output - nothing reported at all
The TestApp debug - reports BUILD SUCCESSFUL
I proceeded to then examine the main.xml used for the layout and on validation in NetBeans it reports "cvc-elt.1: Cannot find the declaration of element 'LinearLayout'"
My main.xml looks like this:
<?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:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<Button
android:id="#+id/used_cars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/used_cars" />
<Button
android:id="#+id/used_vans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/used_vans" />
<Button
android:id="#+id/dealers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dealers" />
</LinearLayout>
I've trawled for info on how to fix this and can't find an answer
Could someone be kind enough to please advise if i'm missing something fundamental?
Thanks in advance
Barry
I've went through the logcat info and found nothing so i decided to create a new app from scratch and copy over the info and it runs fine
If i do find any other info on what caused the issue i'll be sure to post it up
I can only put it down to a config error atm
Kind Regards
Barry

Beginner Android why is "id" is "Unknown member" with R.id?

I'm sure this is something dead simple as it's my first android app with code (the hello world example I did was just assigning a value to a string in XML). My problem is when trying to get the reference for my button in my variable then the id as in R.id is not defined?
The compiler error is in a comment in the code below where it occurs:
package com.geeksonhugs.simplecalc;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity
{
private Button AddButton;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AddButton = (Button)findViewById(R.id.btnAdd);
//"Unknown member 'id' of 'com.geeksonhugs.simplecalc.R'"
//AddButton.setOnClickListener(this);
}
}
XML layout file:
<?xml version='1.0' encoding='utf-8' ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LayoutRoot"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtFirstNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="#string/strFirstNum" />
<EditText
android:id="#+id/edtFirstNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="" />
<TextView
android:id="#+id/txtSecondNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="#string/strSecondNum" />
<EditText
android:id="#+id/edtSecondNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="" />
<Button
android:id="#+id/btnAdd"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="#string/strAdd"
android:gravity="center" />
<TextView
android:id="#+id/txtResult"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="" />
</LinearLayout>
I resolved the issue by deleting the bin folder and recompiling using the AIDE App.
The R class is code-generated for you by the Android build tools when you build your project. This means there are four possibilities:
You have not tried building the project yet, in which case, try that.
Eclipse doesn't think it needs to build the project for some reason -- try Project > Clean from the Eclipse menu (only relevant if you are using Eclipse, of course).
There is some bug in your manifest or one of your resources that is preventing R from being built. There should be Eclipse error indicators for this.
You do not have an android:id attribute in your layout, and therefore there is no R.id available.
Please make sure the xml file you pasted is called main.xml and under layout folder.
And try to generate the R file again.
That may help.
For those using AIDE having issues referencing Id, try deleting the "gen folder" located in the bin folder and recompile. The problem is the R.java class did not create a constructor called Id. So deleting the gen folder containing the R.java class and recompiling solves this issue.
You must add id to a component in the XML file. Like this:
android:id="#+id/buton1"
Now can you click mainActivity.java and write code "R.id." you a see hint to write "buton1" and no error of "id"

Create Layout and test the changes on the emulator failed

i have the problem, that if i create a new layout and change the layout in the graphical layout for example add a button or a textfield to the layout, that the application canĀ“t be installed on the emulated device. I get the unusable error "Failed to install *.apk on device 'emulator-5556': timeout
Launch canceled!".
If i remove the button or textfield then the emulator runs the application. I tested many things. I removed Eclipse and the Android SDK. Installed different Versions of the Eclipse Software (Classic, JAVAEE) and then installed the android SDK every time new. Nothing changed. I deleted the .android folder in my Windows Userprofile. But nothing changed.
What is wrong.
The Code of my layout:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
the code of the Activity:
package de.androidpraxis.HelloAndroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
}
}
i hope someone can help me. Thanks in advance.
greetings
edit:
I found something out. I have a project with a standard layout and an folder for land-layout. If i delete the land-layout folder with the xml files in that the application runs in the emulator. How could i do it right without deleting the other folder?
> I get the unusable error "Failed to install *.apk on device 'emulator-5556':
> timeout Launch
this issue has nothing to do with your layout design.
this is a adb issue.
try executing this command from any terminal or console window
prior to installing your application
path/to/your/android-sdk/platform-tools/.adb kill-server
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
You can try this new layout xml file. And, you should notice that, this file name "layout.xml" and put it in layout folder. But, I don't think this is a problem, because when you don't do this will see error when compile

Android problem

Hi iam working on android getting the following problem for my login but i didn't got my mistake... The error notice is the application has been terminated unexpectedly
my code is
package layout.program;
import android.app.Activity;
import android.os.Bundle;
public class Tablelayout extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.tablelayout);
}
}
tablelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow android:id="#+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content" android:text="TextView" android:id="#+id/textView1" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="wrap_content"></TextView>
<EditText android:id="#+id/editText1" android:layout_height="wrap_content" android:layout_width="fill_parent">
<requestFocus></requestFocus>
</EditText>
</TableRow>
</TableLayout>
Try Cleaning your Project..
By Selecting the Project and then go to top project option and then select clean.
and then select OK..
Sometimes Changes are not made in R.java...Thats y this error comes
Your code is working fine at my end..please look in your code if there is anything which is causing the exception..Try to debug with debugger....
There's nothing wrong with your code or xml, so it has to be an error in your manifest.
As this application is just a stub, why not do this:
Create a new Android project, call it anything you like.
Call the activity 'TableLayoutActivity'
Put your tablelayout.xml into the layout folder.
Change the automatically generated code in TablelayoutActivity.java to set the content view from setContentView(R.layout.main) to setContentView(R.layout.tablelayout)
This should work, then have a look at the manifest in the new project, to see where you went wrong in your original project.
change the class name and try again,also check if the activity name mentioned in the android manifest is correct.

Categories

Resources