Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:24:46+00:00 2026-06-11T22:24:46+00:00

I’m new to Android development and I have this strange problem.. Depending on the

  • 0

I’m new to Android development and I have this strange problem.. Depending on the order of my layout the app works perfectly or just crashes before it’s opened.

My java code:

package com.exmple.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import android.view.View;

public class HelloAndroid extends Activity{
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

            // According to logcat. Below is the error line
    Button myButton = (Button) findViewById(R.id.button1);
    myButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
                        Toast.makeText(HelloAndroid.this, "ImageButton clicked!", Toast.LENGTH_SHORT).show();
                }
    });
}
}

And the layout XML:

<?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" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text1" /> 

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text1" />
</LinearLayout>

And the string XML:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="text1">This is the first text!</string>
<string name="text2">This is the second text!</string>
<string name="app_name">Hello, Android</string>

</resources>

Problem: If I move the textview above the button the program crashes. I can’t see why this happens.

So: Am I retarded or what’s the problem?

=============================
I have test the problem and yes there is issue, Here is lgocat

02-02 02:33:00.433: E/AndroidRuntime(2729): FATAL EXCEPTION: main
02-02 02:33:00.433: E/AndroidRuntime(2729): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.android.testing/com.my.android.testing.HelloAndroid}: java.lang.ClassCastException: android.widget.TextView
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.os.Looper.loop(Looper.java:130)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.app.ActivityThread.main(ActivityThread.java:3683)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at java.lang.reflect.Method.invokeNative(Native Method)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at java.lang.reflect.Method.invoke(Method.java:507)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at dalvik.system.NativeStart.main(Native Method)
02-02 02:33:00.433: E/AndroidRuntime(2729): Caused by: java.lang.ClassCastException: android.widget.TextView
02-02 02:33:00.433: E/AndroidRuntime(2729):     at com.my.android.testing.TestAndActivity.onCreate(HelloAndroid.java:16)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-02 02:33:00.433: E/AndroidRuntime(2729):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-02 02:33:00.433: E/AndroidRuntime(2729):     ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:24:48+00:00Added an answer on June 11, 2026 at 10:24 pm

    clean your project will solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.