This is what I'm doing in the Application class:
#Override
public void onCreate() {
super.onCreate();
CyborgBuilder.startCyborg(new CyborgConfiguration(this, R.layout.cyborgview__auto_reply, BasicModulePack.class));
}
This is how cyborgview__auto_reply.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<com.nu.art.cyborg.core.CyborgView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cyborg="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
cyborg:controller="com.hedshafran.autoreply.controllers.Controller_PermissionScreen"
cyborg:tag="Controller_Permission"/>
And this is what I'm doing in the Controller_PermissionScreen class that causes the crash:
createNewLayerBuilder().setControllerType(Controller_MainScreen.class).setLayoutId(R.layout.controller__main_screen).build();
That causes the crash, which looks like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hedshafran.autoreply, PID: 17910
java.lang.RuntimeException: Unable to resume activity {com.hedshafran.autoreply/com.nu.art.cyborg.core.CyborgActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.nu.art.cyborg.core.CyborgStackController$StackLayerBuilder com.nu.art.cyborg.core.CyborgStackController.createLayerBuilder()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3791)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3832)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.nu.art.cyborg.core.CyborgStackController$StackLayerBuilder com.nu.art.cyborg.core.CyborgStackController.createLayerBuilder()' on a null object reference
at com.nu.art.cyborg.core.CyborgController.createNewLayerBuilder(CyborgController.java:506)
at com.hedshafran.autoreply.controllers.Controller_PermissionScreen.onResume(Controller_PermissionScreen.java:35)
at com.nu.art.cyborg.core.CyborgController.dispatchLifeCycleEvent(CyborgController.java:270)
at com.nu.art.cyborg.core.CyborgActivityBridgeImpl.dispatchLifecycleEvent(CyborgActivityBridgeImpl.java:476)
at com.nu.art.cyborg.core.CyborgActivityBridgeImpl.onResume(CyborgActivityBridgeImpl.java:213)
at com.nu.art.cyborg.core.CyborgActivity.onResume(CyborgActivity.java:155)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1277)
at android.app.Activity.performResume(Activity.java:7088)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3768)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3832)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
How can I avoid that crash and open a new CyborgController the proper way?
Your cyborgview__auto_reply.xml should utilize the CyborgStackConroller that will contain your Controller_PermissionScreen, like so:
<?xml version="1.0" encoding="utf-8"?>
<com.nu.art.cyborg.core.CyborgView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cyborg="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/CV_RootStack"
cyborg:controller="com.nu.art.cyborg.core.CyborgStackController"
cyborg:rootController="com.hedshafran.autoreply.controllers.Controller_PermissionScreen"
cyborg:rootTag="Controller_Permission"
cyborg:tag="RootStack"
/>
Point is you can only use the createNewLayerBuilder api if the controller that calls this method is in a stack. Otherwise use the getControllerById(R.id.CV_RootStack) and create a new layer builder.
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
This is my source code,it seams the program throw exception at line 41.
public class LaunchActivity extends ACtivity{
//Drawable
private ColorDrawable mBgDrawable;
#Override
protected int getContentLayoutId() {
return R.layout.activity_launch;
}
#Override
protected void initWidows() {
super.initWidows();
//拿到根布局
View root = findViewById(R.id.activity_launch);
//获取颜色
int color = UiCompat.getColor(getResources(),R.color.colorPrimary);
//创建一个Drawable
ColorDrawable drawable = new ColorDrawable(color);
//设置给背景
root.setBackground(drawable); **//line 41**
mBgDrawable = drawable;
}
the layout source code (activity_launch.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_launch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:orientation="vertical"
tools:context="net.qiujuer.italker.push.LaunchActivity">
.....
and this is the error information.
(Does it means the View ('root') I get is a null object ?)
FATAL EXCEPTION: main
Process: net.qiujuer.italker.push, PID: 3046
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.qiujuer.italker.push/net.qiujuer.italker.push.LaunchActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackground(android.graphics.drawable.Drawable)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackground(android.graphics.drawable.Drawable)' on a null object reference
at net.qiujuer.italker.push.LaunchActivity.initWidows(LaunchActivity.java:41)
at net.qiujuer.italker.common.app.ACtivity.onCreate(ACtivity.java:16)
at android.app.Activity.performCreate(Activity.java:7130)
at android.app.Activity.performCreate(Activity.java:7121)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
This is my first attempt to ask questions on stack overflow. Thank you for your help.
Seems that you have declared layout name in root-view so view is not initialized.
Please check findViewById(R.id.activity_launch) for rootview and updated accordingly.
I inherited a project, trying to understand and solve an old bug.
When I start an activity and let it sit for a bit (sometimes it's almost immediate), but it appears to go into a pause state or something and attempts to reload the activity and gets an error.
"Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String ... ' on a null object reference"
I found that when I add this to my activity:
#Override
public void onSaveInstanceState(Bundle savedInstanceState)
{
//super.onSaveInstanceState(savedInstanceState);
}
It appears to work perfectly.
However, when I uncomment the line above to super.onSaveInstanceState(savedInstanceState);, I get the error again.
My activity is extending the ActionBarActivity, if that is helpful.
Any help would be appreciated. Thank you!
Related Code:
#Override
protected void prepareLayout() {
textMessage = (TextView) findViewById(R.id.textMessage);
textNotes = (EditText) findViewById(R.id.textNotes);
textMessage.setText(getOneOfMyItems().getText());
// ... the above line is where the problem error is thrown.
}
Stack Trace:
Process: com.myproj.myproj, PID: 9272
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myproj.myproj/com.myproj.activities.MyActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.myproj.data.MyItems.getText()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3384)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5433)
at android.app.ActivityThread.access$1200(ActivityThread.java:226)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1810)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7270)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.myproj.data.MyItems.getText()' on a null object reference
at com.myproj.xyz.MyFragment.prepareLayout(MyFragment.java:44)
at com.myproj.fragments.BaseFragment.prepareAndSetView(BaseFragment.java:49)
at at com.myproj.xyz.BaseMyFragment.onCreateView(BaseMyFragment.java:21)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2143)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2089)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1129)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2143)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:615)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
at android.app.Activity.performStart(Activity.java:6943)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3384)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5433)
at android.app.ActivityThread.access$1200(ActivityThread.java:226)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1810)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7270)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
First of all, I'm starting at Android, so maybe I'm asking a stupid question. Oh, and sorry for my English.
I have an Activity that receives an Object when it starts (in the previous activity's Intent) and I want to set severals views (ImageView and TextViews) in the Java file. I have looked for the way to do it, and this is what I think I need.
The XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/party"
tools:context=".activities.PartyActivity">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".activities.PartyActivity"
android:id="#+id/head">
<!--Party-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/photo"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.PartyActivity">
<!--Dia/hora-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/date"/>
<!--Dirección-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/currentCity"
android:id="#+id/direction"/>
<!--Precio-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/currentCity"
android:id="#+id/price"/>
</RelativeLayout>
</RelativeLayout>
<!--Descripcion-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/head"
android:id="#+id/description"/>
<!--Mapa-->
And this is the class:
public class PartyActivity extends Activity {
private RelativeLayout partyLayout;
private Party party;
private ImageView photoView;
private TextView dateView;
private TextView directionVew;
private TextView priceView;
private TextView descriptionView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_party);
partyLayout = (RelativeLayout)findViewById(R.id.party);
party = (Party)getIntent().getExtras().getSerializable("Party");
setParty();
}
private void setParty(){
partyLayout.removeAllViews();
photoView = (ImageView)findViewById(R.id.photo);
dateView = (TextView)findViewById(R.id.date);
directionVew = (TextView)findViewById(R.id.direction);
priceView = (TextView)findViewById(R.id.price);
descriptionView = (TextView)findViewById(R.id.description);
photoView.setImageBitmap(party.getPhoto());
dateView.setText(Session.getInstance().getDateFormat().format(party.getDate().getTime()));
directionVew.setText(party.getDirection());
priceView.setText(party.getPrice().toString());
descriptionView.setText(party.getDescripcion());
setContentView(photoView);
setContentView(dateView);
setContentView(directionVew);
setContentView(priceView);
setContentView(descriptionView);
}
When I try to go to the activity, the application shuts down. I have debugged it and the Party object has been received correctly, but in the setParty method it throws this exception:
04-08 14:21:08.619 14680-14680/trebolete.keloke E/AndroidRuntime: FATAL EXCEPTION: main
Process: trebolete.keloke, PID: 14680 java.lang.RuntimeException: Unable to start activity ComponentInfo{trebolete.keloke/trebolete.keloke.activities.PartyActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
at trebolete.keloke.activities.PartyActivity.setParty(PartyActivity.java:46)
at trebolete.keloke.activities.PartyActivity.onCreate(PartyActivity.java:33)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
If I remove the line partyLayout.removeAllViews(); it throws this exception:
04-09 13:47:44.101 2576-2576/trebolete.keloke E/AndroidRuntime: FATAL EXCEPTION: main
Process: trebolete.keloke, PID: 2576
java.lang.RuntimeException: Unable to start activity ComponentInfo{trebolete.keloke/trebolete.keloke.activities.PartyActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4309)
at android.view.ViewGroup.addView(ViewGroup.java:4145)
at android.view.ViewGroup.addView(ViewGroup.java:4117)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:423)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:404)
at android.app.Activity.setContentView(Activity.java:2186)
at trebolete.keloke.activities.PartyActivity.setParty(PartyActivity.java:52)
at trebolete.keloke.activities.PartyActivity.onCreate(PartyActivity.java:33)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Any help?
As you have already set parent view in onCreate() function.
setContentView(R.layout.activity_party);
Will set the parent layout for the current activity.Which you have already initailzed this in onCreate() function of activity.
All these views(
photoView, dateView, directionVew,
priceView , descriptionView
) are child layouts of activity_party . You don't need to perform setContentView() on these views.
Those views will automatically display your updated data , which you have updated in following line of codes :
photoView.setImageBitmap(party.getPhoto());
dateView.setText(Session.getInstance().getDateFormat().format(party.getDate().getTime()));
directionVew.setText(party.getDirection());
priceView.setText(party.getPrice().toString());
descriptionView.setText(party.getDescripcion());
Since you called partyLayout.removeAllViews(); you removed all views from the layout. That's why findViewById() returns null.
I am getting the following error in Android Studio and I am unable to resolve it:
07-06 19:44:41.798 4491-4491/com.example.first_app D/AndroidRuntime: Shutting down VM
07-06 19:44:41.799 4491-4491/com.example.first_app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.first_app, PID: 4491
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first_app/com.example.first_app.welcome}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.view.View.toString()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.view.View.toString()' on a null object reference
at com.example.first_app.welcome.onCreate(welcome.java:22)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-06 19:44:44.696 4491-4497/com.example.first_app W/art: Suspending all threads took: 46.612ms
07-06 19:44:46.517 4491-4491/com.example.first_app I/Process: Sending signal. PID: 4491 SIG: 9
THIS IS THE ERROR I M INCURRING
CODE FOR welcome.java
public class welcome extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
TextView my_msg;
String name;
my_msg= (TextView)findViewById(R.id.textView3);
name= "Welcome " +findViewById(R.id.textView2).toString();
my_msg.setText(name);
}
}
XML CODE FOR welcome.xml ...Please refer it..it only shows the message on screen "welcome Name"..the name is entered by user through activity_form.java
<?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:weightSum="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView3"
android:layout_gravity="center"
android:layout_weight="1" />
</LinearLayout>
First the way to solve your exception to type cast the View and getText from that View
(TextView) findViewById(R.id.textView2).getText().toString();
So the final String will look like
name= "Welcome " + (TextView) findViewById(R.id.textView2).getText().toString();
SUGGESTION
Use proper naming conventions for views, Rather than naming view1 view2 etc
Some time ther is not error its run without error but most of time got error in this code, I try many thing for this. I try call this code on onStart() and I try this on onActivityCreted() too. but i get same error. This is my coding for show previous chat. I got error in limit().
final ListView listView = getListView();
mChatListAdapter = new FirebaseListAdapter<>(mFirebaseRef.limit(50), Chat.class, R.layout.chat_item, R.layout.chat_item_other,
R.layout.third_layout_chat, R.layout.fourth_layout_chat, getActivity(), chat_id);
listView.setAdapter(mChatListAdapter);
mChatListAdapter.registerDataSetObserver(new DataSetObserver() {
#Override
public void onChanged() {
super.onChanged();
listView.setSelection(mChatListAdapter.getCount() - 1);
}
});
This is error.
FATAL EXCEPTION: main Process: com.socialapp.android, PID: 8112 Theme: themes:{} java.lang.RuntimeException: Unable to start activity ComponentInfo{com.socialapp.android/com.socialapp.chat.ChatViewActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.firebase.client.Query com.firebase.client.Firebase.limit(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.firebase.client.Query com.firebase.client.Firebase.limit(int)' on a null object reference
at com.socialapp.chat.ChatViewFragment.onStart(ChatViewFragment.java:609)
at android.app.Fragment.performStart(Fragment.java:2244)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1002)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1958)
at android.app.FragmentController.dispatchStart(FragmentController.java:163)
at android.app.Activity.performStart(Activity.java:6274)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)