English 中文(简体)
申请扔下Null PointerException
原标题:Application throws a NullPointerException
  • 时间:2011-04-07 10:02:17
  •  标签:
  • android

我开展了3项活动。

  1. ElecBillActative

  2. AddBillActivity

  3. 活动

我在第二次活动中成功地利用了一名实习生进入了第二次活动,但一旦我在第二次活动中点击了次特顿,我就成为一个例外。

我尝试了许多方法,但我无法理解这一问题。

这是我的标志

E/AndroidRuntime(  506): FATAL EXCEPTION: main
E/AndroidRuntime(  506): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sai.android.billing/com.sai.android.billing.活动}: java.lang.NullPointerException
E/AndroidRuntime(  506):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1544)
E/AndroidRuntime(  506):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
E/AndroidRuntime(  506):        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime(  506):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
E/AndroidRuntime(  506):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  506):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  506):        at android.app.ActivityThread.main(ActivityThread.java:3647)
E/AndroidRuntime(  506):        at java.lang.reflect.Method.invokeNative(NativeMethod)
E/AndroidRuntime(  506):        at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(  506):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(  506):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(  506):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  506): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  506):        at com.sai.android.billing.活动.<init>(活动.java:21)
E/AndroidRuntime(  506):        at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(  506):        at java.lang.Class.newInstance(Class.java:1409)
E/AndroidRuntime(  506):        at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(  506):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
E/AndroidRuntime(  506):        ... 11 more
W/ActivityManager(   70):   Force finishing activity com.sai.android.billing/.活动
W/ActivityManager(   70):   Force finishing activity com.sai.android.billing/.AddBillActivity
W/ActivityManager(   70): Activity pause timeout for HistoryRecord{4079d8f8 com.sai.android.billing/.活动}
I/ARMAssembler(   70): generated scanline__00000177:03515104_00001001_00000000 [91 ipp] (114 ins) at [0x445b36e0:0x445b38a8] in 1634844 ns
I/Process (  506): Sending signal. PID: 506 SIG: 9
I/ActivityManager(   70): Process com.sai.android.billing (pid 506) has died.
E/InputDispatcher(   70): channel  4060e840 com.sai.android.billing/com.sai.android.billing.ElecBillingActivity (server)  ~ Consumer closed input channel or an error occurred.  events=0x8
E/InputDispatcher(   70): channel  4060e840 com.sai.android.billing/com.sai.android.billing.ElecBillingActivity (server)  ~ Channel is unrecoverably broken and will be disposed!
I/WindowManager(   70): WIN DEATH: Window{4060e840 com.sai.android.billing/com.sai.android.billing.ElecBillingActivity paused=false}
I/WindowManager(   70): WIN DEATH: Window{406f4868 com.sai.android.billing/com.sai.android.billing.AddBillActivity paused=true}
E/InputDispatcher(   70): Received spurious receive callback for unknown input channel.  fd=151, events=0x8
W/InputManagerService(   70): Got RemoteException sending setActive(false) notification to pid 506 uid 10038

我还为我的

As my problem seems to big and my class files are too big I provided the download link here.
As I am a new user I am unable to post the screenshots here.

最佳回答

According to the logs you got a NullPointerException in ResultActivity.java on line 21... taking a look into your source code, this is caused by calling getIntent() which is a member function of Activity which can only be called after the Activity is created. Therefore, move your initialization code into the onCreate method.

3. 将贵成员的定义改为:

private TextView resultOk;
int highLimit,lowLimit,highRate,lowRate,defaultRate,amount;
Bundle bundle;
String userName;
String meterNumber;
String prevReading;
String currReading;
int pR;
int cR;
int units;
String u;
String a;

此外,请打电话getIntent (.getExtras(),将其储存在bundle上。 但是,由于你从未在<条码>中添加任何内容,<条码>/条码>,<条码>bundle将改为<条码>null,在你尝试<条码>bundle.getString(......)时,它将向另一个<条码>NullPointerException!

作出的第一个改动是提供<代码>android:id属以下表格:xml文档。 将其编为<代码>radios,并在<代码>AddBillActective中增加这一行文:

public static RadioGroup radios;

以及<代码>的这个行文 方法:

radios = (RadioGroup)findViewById(R.id.radios);

然后修改<代码>addTask

Intent intent1 = new Intent(AddBillActivity.this, ResultActivity.class);
intent1.putExtra("bill_name", billNameEditText.getText().toString());
intent1.putExtra("bill_number", billNumEditText.getText().toString());
intent1.putExtra("bill_previous", billPrevEditText.getText().toString());
intent1.putExtra("bill_current", billCurrEditText.getText().toString());
intent1.putExtra("radio", radios.getCheckedRadioButtonId());
startActivity(intent1);

And now you can get all those extras in your onCreate method in ResultActivity:

bundle = getIntent().getExtras();
userName = bundle.getString("bill_name");
meterNumber = bundle.getString("bill_number");
prevReading = bundle.getString("bill_previous");
currReading = bundle.getString("bill_current");
pR = Integer.parseInt(prevReading);
cR = Integer.parseInt(currReading);
units = pR - cR;
u = bundle.getString(String.valueOf(units));
a = bundle.getString(String.valueOf(units));

(b) 应:

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签