[英]I don't understand where is the error for my android apps
the codes are given below run properly but when I click the start activity button the apps shows the error: "Tasbeeh has unfortunately stopped" 下面的代码运行正常但是当我点击开始活动按钮时,应用程序显示错误:“Tasbeeh不幸停止了”
here is my code 这是我的代码
send.xml send.xml
<?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/tvQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a..." />
<RadioGroup
android:id="@+id/rgAnswers"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rCrazy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Crazy" />
<RadioButton
android:id="@+id/rSexy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUPER SEXY" />
<RadioButton
android:id="@+id/rBoth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Both" />
</RadioGroup>
<Button
android:id="@+id/bReturn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Return" />
<TextView
android:id="@+id/tvText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
the get.xml get.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/etSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
<Button
android:id="@+id/bSA"
android:layout_below="@id/etSend"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StartActivity" />
<Button
android:id="@+id/bSAFR"
android:layout_toLeftOf="@id/bSA"
android:layout_alignTop="@id/bSA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StartActivityForResult" />
<TextView
android:id="@+id/tvGot"
android:layout_below="@id/bSAFR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</RelativeLayout>
Data.java Data.java
package com.firstone.nrshoukhin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Data extends Activity implements OnClickListener{
Button start, startFor;
EditText sendET;
TextView gotAnswer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.get);
initialize();
}
private void initialize() {
// TODO Auto-generated method stub
start = (Button) findViewById(R.id.bSA);
startFor = (Button) findViewById(R.id.bSAFR);
sendET = (EditText) findViewById(R.id.etSend);
gotAnswer = (TextView) findViewById(R.id.tvGot);
start.setOnClickListener(this);
startFor.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.bSA:
String bread = sendET.getText().toString();
Bundle basket = new Bundle();
basket.putString("key", bread);
Intent a = new Intent(Data.this,OpenedClass.class);
startActivity(a);
break;
case R.id.bSAFR:
break;
}
}
}
OpenedClass.java OpenedClass.java
package com.firstone.nrshoukhin;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class OpenedClass extends Activity implements OnClickListener, OnCheckedChangeListener{
TextView question, test;
Button returnData;
RadioGroup selectionList;
String gotBread;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
intialize();
Bundle gotBasket = getIntent().getExtras();
gotBread = gotBasket.getString("key");
question.setText(gotBread);
}
private void intialize() {
// TODO Auto-generated method stub
question = (TextView) findViewById(R.id.tvQuestion);
test = (TextView) findViewById(R.id.tvText);
returnData = (Button) findViewById(R.id.bReturn);
returnData.setOnClickListener(this);
selectionList = (RadioGroup) findViewById(R.id.rgAnswers);
selectionList.setOnCheckedChangeListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch(arg1){
case R.id.rCrazy:
break;
case R.id.rSexy:
break;
case R.id.rBoth:
break;
}
}
}
the log cat 原木猫
12-11 23:14:25.726: D/dalvikvm(826): GC_FOR_ALLOC freed 29K, 6% free 2555K/2704K, paused 193ms, total 197ms
12-11 23:14:25.946: I/dalvikvm-heap(826): Grow heap (frag case) to 6.607MB for 4194320-byte allocation
12-11 23:14:26.086: D/dalvikvm(826): GC_FOR_ALLOC freed <1K, 3% free 6651K/6804K, paused 137ms, total 137ms
12-11 23:14:30.746: D/gralloc_goldfish(826): Emulator without GPU emulation detected.
12-11 23:14:34.366: D/dalvikvm(826): GC_FOR_ALLOC freed 22K, 2% free 7922K/8064K, paused 149ms, total 165ms
12-11 23:14:34.805: I/Choreographer(826): Skipped 36 frames! The application may be doing too much work on its main thread.
12-11 23:14:35.705: I/Choreographer(826): Skipped 184 frames! The application may be doing too much work on its main thread.
12-11 23:14:37.285: I/Choreographer(826): Skipped 30 frames! The application may be doing too much work on its main thread.
12-11 23:14:44.055: I/Choreographer(826): Skipped 48 frames! The application may be doing too much work on its main thread.
12-11 23:14:45.935: I/Choreographer(826): Skipped 66 frames! The application may be doing too much work on its main thread.
12-11 23:14:52.416: D/AndroidRuntime(826): Shutting down VM
12-11 23:14:52.416: W/dalvikvm(826): threadid=1: thread exiting with uncaught exception (group=0x41465700)
12-11 23:14:52.506: E/AndroidRuntime(826): FATAL EXCEPTION: main
12-11 23:14:52.506: E/AndroidRuntime(826): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.firstone.nrshoukhin.OpenedClass (has extras) }
12-11 23:14:52.506: E/AndroidRuntime(826): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.app.Activity.startActivityForResult(Activity.java:3390)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.app.Activity.startActivityForResult(Activity.java:3351)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.app.Activity.startActivity(Activity.java:3587)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.app.Activity.startActivity(Activity.java:3555)
12-11 23:14:52.506: E/AndroidRuntime(826): at com.firstone.nrshoukhin.Data.onClick(Data.java:48)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.view.View.performClick(View.java:4240)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.view.View$PerformClick.run(View.java:17721)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.os.Handler.handleCallback(Handler.java:730)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.os.Handler.dispatchMessage(Handler.java:92)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.os.Looper.loop(Looper.java:137)
12-11 23:14:52.506: E/AndroidRuntime(826): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 23:14:52.506: E/AndroidRuntime(826): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 23:14:52.506: E/AndroidRuntime(826): at java.lang.reflect.Method.invoke(Method.java:525)
12-11 23:14:52.506: E/AndroidRuntime(826): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 23:14:52.506: E/AndroidRuntime(826): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 23:14:52.506: E/AndroidRuntime(826): at dalvik.system.NativeStart.main(Native Method)
12-11 23:15:01.525: I/Process(826): Sending signal. PID: 826 SIG: 9
12-11 23:15:03.145: D/dalvikvm(873): GC_FOR_ALLOC freed 32K, 6% free 2556K/2708K, paused 41ms, total 44ms
12-11 23:15:03.187: I/dalvikvm-heap(873): Grow heap (frag case) to 6.608MB for 4194320-byte allocation
12-11 23:15:03.335: D/dalvikvm(873): GC_FOR_ALLOC freed <1K, 3% free 6652K/6808K, paused 140ms, total 140ms
12-11 23:15:04.395: I/Choreographer(873): Skipped 51 frames! The application may be doing too much work on its main thread.
12-11 23:15:04.415: D/gralloc_goldfish(873): Emulator without GPU emulation detected.
12-11 23:16:00.366: D/dalvikvm(918): GC_FOR_ALLOC freed 36K, 6% free 2555K/2708K, paused 286ms, total 288ms
12-11 23:16:00.576: I/dalvikvm-heap(918): Grow heap (frag case) to 6.607MB for 4194320-byte allocation
12-11 23:16:00.696: D/dalvikvm(918): GC_FOR_ALLOC freed <1K, 3% free 6651K/6808K, paused 116ms, total 117ms
12-11 23:16:03.667: D/gralloc_goldfish(918): Emulator without GPU emulation detected.
12-11 23:16:07.086: D/dalvikvm(918): GC_FOR_ALLOC freed 23K, 2% free 7924K/8064K, paused 184ms, total 204ms
12-11 23:16:07.906: I/Choreographer(918): Skipped 97 frames! The application may be doing too much work on its main thread.
12-11 23:16:13.015: I/Choreographer(918): Skipped 55 frames! The application may be doing too much work on its main thread.
12-11 23:16:14.605: I/Choreographer(918): Skipped 34 frames! The application may be doing too much work on its main thread.
12-11 23:16:19.175: I/Choreographer(918): Skipped 93 frames! The application may be doing too much work on its main thread.
12-11 23:16:40.385: I/Choreographer(918): Skipped 91 frames! The application may be doing too much work on its main thread.
12-11 23:29:31.275: D/AndroidRuntime(966): Shutting down VM
12-11 23:29:31.295: W/dalvikvm(966): threadid=1: thread exiting with uncaught exception (group=0x41465700)
12-11 23:29:31.415: E/AndroidRuntime(966): FATAL EXCEPTION: main
12-11 23:29:31.415: E/AndroidRuntime(966): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.IllegalStateException: Unable to get package info for com.firstone.nrshoukhin; is package not installed?
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.LoadedApk.makeApplication(LoadedApk.java:509)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4417)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.os.Looper.loop(Looper.java:137)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 23:29:31.415: E/AndroidRuntime(966): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 23:29:31.415: E/AndroidRuntime(966): at java.lang.reflect.Method.invoke(Method.java:525)
12-11 23:29:31.415: E/AndroidRuntime(966): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 23:29:31.415: E/AndroidRuntime(966): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 23:29:31.415: E/AndroidRuntime(966): at dalvik.system.NativeStart.main(Native Method)
12-11 23:29:31.415: E/AndroidRuntime(966): Caused by: java.lang.IllegalStateException: Unable to get package info for com.firstone.nrshoukhin; is package not installed?
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:369)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.LoadedApk.getClassLoader(LoadedApk.java:322)
12-11 23:29:31.415: E/AndroidRuntime(966): at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
12-11 23:29:31.415: E/AndroidRuntime(966): ... 11 more
12-11 23:29:43.665: D/dalvikvm(997): GC_FOR_ALLOC freed 43K, 6% free 2555K/2716K, paused 144ms, total 158ms
12-11 23:29:43.865: I/dalvikvm-heap(997): Grow heap (frag case) to 6.607MB for 4194320-byte allocation
12-11 23:29:44.075: D/dalvikvm(997): GC_FOR_ALLOC freed <1K, 3% free 6651K/6816K, paused 207ms, total 207ms
12-11 23:29:47.115: D/gralloc_goldfish(997): Emulator without GPU emulation detected.
12-11 23:29:50.475: D/dalvikvm(997): GC_FOR_ALLOC freed 23K, 2% free 7923K/8064K, paused 160ms, total 181ms
12-11 23:29:51.355: I/Choreographer(997): Skipped 110 frames! The application may be doing too much work on its main thread.
12-11 23:29:54.466: I/Choreographer(997): Skipped 66 frames! The application may be doing too much work on its main thread.
12-11 23:29:56.016: I/Choreographer(997): Skipped 43 frames! The application may be doing too much work on its main thread.
12-11 23:29:59.826: D/AndroidRuntime(997): Shutting down VM
12-11 23:29:59.826: W/dalvikvm(997): threadid=1: thread exiting with uncaught exception (group=0x41465700)
12-11 23:29:59.886: E/AndroidRuntime(997): FATAL EXCEPTION: main
12-11 23:29:59.886: E/AndroidRuntime(997): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.firstone.nrshoukhin/com.firstone.nrshoukhin.OpenedClass}; have you declared this activity in your AndroidManifest.xml?
12-11 23:29:59.886: E/AndroidRuntime(997): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.app.Activity.startActivityForResult(Activity.java:3390)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.app.Activity.startActivityForResult(Activity.java:3351)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.app.Activity.startActivity(Activity.java:3587)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.app.Activity.startActivity(Activity.java:3555)
12-11 23:29:59.886: E/AndroidRuntime(997): at com.firstone.nrshoukhin.Data.onClick(Data.java:48)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.view.View.performClick(View.java:4240)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.view.View$PerformClick.run(View.java:17721)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.os.Handler.handleCallback(Handler.java:730)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.os.Handler.dispatchMessage(Handler.java:92)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.os.Looper.loop(Looper.java:137)
12-11 23:29:59.886: E/AndroidRuntime(997): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 23:29:59.886: E/AndroidRuntime(997): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 23:29:59.886: E/AndroidRuntime(997): at java.lang.reflect.Method.invoke(Method.java:525)
12-11 23:29:59.886: E/AndroidRuntime(997): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 23:29:59.886: E/AndroidRuntime(997): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 23:29:59.886: E/AndroidRuntime(997): at dalvik.system.NativeStart.main(Native Method)
12-11 23:30:03.485: I/Process(997): Sending signal. PID: 997 SIG: 9
12-11 23:30:05.625: D/dalvikvm(1028): GC_FOR_ALLOC freed 47K, 7% free 2556K/2720K, paused 209ms, total 215ms
12-11 23:30:05.725: I/dalvikvm-heap(1028): Grow heap (frag case) to 6.608MB for 4194320-byte allocation
12-11 23:30:05.855: D/dalvikvm(1028): GC_FOR_ALLOC freed <1K, 3% free 6652K/6820K, paused 125ms, total 125ms
12-11 23:30:06.995: I/Choreographer(1028): Skipped 63 frames! The application may be doing too much work on its main thread.
12-11 23:30:07.015: D/gralloc_goldfish(1028): Emulator without GPU emulation detected.
12-11 23:30:07.365: I/Choreographer(1028): Skipped 39 frames! The application may be doing too much work on its main thread.
It seems, that you didn't put your Bundle
inside Intent
object. 看来,你没有把你的
Bundle
放在Intent
对象里面。
String bread = sendET.getText().toString();
Bundle basket = new Bundle();
basket.putString("key", bread);
Intent a = new Intent(Data.this,OpenedClass.class);
a.putExtras(basket);//set your bundle inside intent
startActivity(a);
Bundle gotBasket = getIntent().getExtras();
gotBread = gotBasket.getString("key");
The gotBasket is null, because you did not passed any extras when you started the activity. gotBasket为null,因为在启动活动时没有传递任何额外内容。
Try with this :In Data.java 试试这个:在Data.java中
Intent a = new Intent(Data.this,OpenedClass.class);
a.putExtra("key", bread);
And in OpenedClass.java: 在OpenedClass.java中:
Bundle gotBasket = getIntent().getExtras();
gotBread = gotBasket.getString("key");
And could You upload error log Then it will be easy to solve problem. 你可以上传错误日志然后很容易解决问题。
Declare OpenedClass in mainfest. 在mainfest中声明OpenedClass。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.