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 7034051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:08:22+00:00 2026-05-28T01:08:22+00:00

I always get this error when i try to run my own programmed App.

  • 0

I always get this error when i try to run my own programmed App.
It’s just a trying App which should on Button click add a TextView.

I have no idea where the problem is. There are no Errors and no Warnings in the Sourcecode.

Here you can see the logcat:

01-11 07:52:02.219: E/AndroidRuntime(698): FATAL EXCEPTION: main
01-11 07:52:02.219: E/AndroidRuntime(698): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{local.roger.AddWidget/local.roger.AddWidget.AddWidgetActivity}: java.lang.NullPointerException
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.os.Looper.loop(Looper.java:137)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.ActivityThread.main(ActivityThread.java:4340)
01-11 07:52:02.219: E/AndroidRuntime(698):  at java.lang.reflect.Method.invokeNative(Native Method)
01-11 07:52:02.219: E/AndroidRuntime(698):  at java.lang.reflect.Method.invoke(Method.java:511)
01-11 07:52:02.219: E/AndroidRuntime(698):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-11 07:52:02.219: E/AndroidRuntime(698):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-11 07:52:02.219: E/AndroidRuntime(698):  at dalvik.system.NativeStart.main(Native Method)
01-11 07:52:02.219: E/AndroidRuntime(698): Caused by: java.lang.NullPointerException
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.Activity.findViewById(Activity.java:1794)
01-11 07:52:02.219: E/AndroidRuntime(698):  at local.roger.AddWidget.AddWidgetActivity.<init>(AddWidgetActivity.java:15)
01-11 07:52:02.219: E/AndroidRuntime(698):  at java.lang.Class.newInstanceImpl(Native Method)
01-11 07:52:02.219: E/AndroidRuntime(698):  at java.lang.Class.newInstance(Class.java:1319)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
01-11 07:52:02.219: E/AndroidRuntime(698):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
01-11 07:52:02.219: E/AndroidRuntime(698):  ... 11 more

The main.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/btn_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_add" />


    <LinearLayout
        android:id="@+id/ll_vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

    </LinearLayout>

</LinearLayout>

The Source Code:

package local.roger.AddWidget;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AddWidgetActivity extends Activity {
    /** Called when the activity is first created. */
    int counter = 0;
    LinearLayout ll_vertical = (LinearLayout)findViewById(R.id.ll_vertical);

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



        Button btn_add = (Button)findViewById(R.id.btn_add);
        btn_add.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v){
                createTextView("TestText_"+counter);



            }
        });
    }

    public void createTextView(String value) {
        TextView txt_test = new TextView(this);
        txt_test.setText(value);
        txt_test.setId(counter);
        counter = counter + 1;
        txt_test.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        ll_vertical.addView(txt_test);

    }
}

Thanks for helping
Regards Roger

  • 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-05-28T01:08:22+00:00Added an answer on May 28, 2026 at 1:08 am

    First declare the ll_vertical variable: LinearLayout ll_vertical ; and then
    put the code ll_vertical = (LinearLayout)findViewById(R.id.ll_vertical); inside the onCreate() method, after setContentView(R.layout.main);
    So now the codes look like:

     LinearLayout ll_vertical;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ll_vertical = (LinearLayout)findViewById(R.id.ll_vertical);
    

    Before you inflate a layout file by calling setContentView(), the system can’t find the items in that layout file.That’s why the NullPointerException comes out.

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

Sidebar

Related Questions

I always get this error when trying to compile my file with Boost::GIL PNG
I am trying to deserialize a stream but I always get this error End
I can't seem to compile ironruby in ruby 1.8.7. I always get this error:
I am using following PHP code for trigger creation but always get error, please
When I run DB.SubmitChanges(); I occasionally get an error that reads: Row not found
So I keep getting this error when trying to compile C++ code using CodeBlocks.
this is my first Android app and I'm trying to use Sockets to send
i am using PHP to run exec() on a script which looks like this:
I always get confused when I am about to use a bit map to
I tried many things but I always get cannot convert string to membershipuser from

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.