这"代码A"是我的基类的代码,我将这个类扩展到另一个类"代码B"。问题是,当我运行我的应用程序时,我的应用程序已停止。我的Base类有什么问题,或者我没有正确调用它们?活动已在清单文件中注册。
代码A
public class PrepaidBase extends Activity {
PrepaidBase pb = new PrepaidBase();
private String number = "";
public void alertDialogShow(Context context, String title, String message, String _number) {
this.number = _number;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
call();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
});
}
public void call()
{
Intent in = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode(number)));
try
{
startActivity(in);
}catch (ActivityNotFoundException e)
{
e.printStackTrace();
}
}
代码B
public class PrepaidLBO extends PrepaidBase {
Button chobeesButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chobeesghantay);
chobeesButton = (Button)findViewById(R.id.chobeesButton);
pb.alertDialogShow(PrepaidLBO.this, "Some Test" , "Text Here too" , "*1234#");
chobeesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
call();
}
});
}
logcat的
06-24 18:34:07.281 2533-2533/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
06-24 18:34:10.168 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 94(16KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 5MB/8MB, paused 1.833ms total 114.739ms
06-24 18:34:10.835 2533-2533/adnan.com.ufone D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
06-24 18:34:14.157 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 39.850ms
06-24 18:34:14.295 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 41 frames! The application may be doing too much work on its main thread.
06-24 18:34:15.103 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 81 frames! The application may be doing too much work on its main thread.
06-24 18:34:15.472 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 36 frames! The application may be doing too much work on its main thread.
06-24 18:34:18.337 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 61 frames! The application may be doing too much work on its main thread.
06-24 18:34:18.931 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 58 frames! The application may be doing too much work on its main thread.
06-24 18:34:19.856 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 94 frames! The application may be doing too much work on its main thread.
06-24 18:34:21.059 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 6.443ms
06-24 18:34:21.406 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 157 frames! The application may be doing too much work on its main thread.
06-24 18:34:24.141 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 39 frames! The application may be doing too much work on its main thread.
06-24 18:34:26.998 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 56 frames! The application may be doing too much work on its main thread.
06-24 18:34:27.414 2533-2533/adnan.com.ufone I/Choreographer﹕ Skipped 40 frames! The application may be doing too much work on its main thread.
06-24 18:34:28.707 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 47.201ms
06-24 18:34:29.101 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 31.696ms
06-24 18:34:29.607 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 37.610ms
06-24 18:34:30.220 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 147.585ms
06-24 18:34:30.360 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6086(146KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 8MB/8MB, paused 51.143ms total 352.611ms
06-24 18:34:30.366 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 6.379ms
06-24 18:34:30.632 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 57.711ms
06-24 18:34:30.645 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 14.495ms
06-24 18:34:30.736 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 236(3KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 8MB/8MB, paused 95.529ms total 346.798ms
06-24 18:34:30.790 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 54.155ms
06-24 18:34:31.194 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 119.068ms
06-24 18:34:31.388 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 1581(37KB) AllocSpace objects, 0(0B) LOS objects, 30% free, 8MB/12MB, paused 80.648ms total 581.160ms
06-24 18:34:31.397 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 8.587ms
06-24 18:34:33.209 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 592.155ms
06-24 18:34:33.368 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 26.443ms
06-24 18:34:33.386 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6587(103KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 12MB/12MB, paused 111.437ms total 1.029s
06-24 18:34:33.638 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 365(5KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 13MB/13MB, paused 66.483ms total 230.992ms
06-24 18:34:34.259 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 178.489ms
06-24 18:34:34.609 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 23.285ms
06-24 18:34:34.627 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 4630(107KB) AllocSpace objects, 1(4MB) LOS objects, 27% free, 10MB/14MB, paused 121.820ms total 959.586ms
06-24 18:34:35.477 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 392.420ms
06-24 18:34:35.637 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 10.761ms
06-24 18:34:35.661 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6057(94KB) AllocSpace objects, 0(0B) LOS objects, 3% free, 14MB/14MB, paused 127.324ms total 713.914ms
06-24 18:34:35.662 2533-2546/adnan.com.ufone I/art﹕ WaitForGcToComplete blocked for 310.554ms for cause HeapTrim
06-24 18:34:36.544 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 418.091ms
06-24 18:34:36.637 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 51.426ms
06-24 18:34:36.657 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 7.696ms
06-24 18:34:36.844 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 2386(37KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 15MB/19MB, paused 141.802ms total 1.153s
06-24 18:34:37.938 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 348.103ms
06-24 18:34:38.227 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 10.882ms
06-24 18:34:38.258 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 8373(130KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 20MB/20MB, paused 182.373ms total 951.554ms
06-24 18:34:38.266 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 7.610ms
06-24 18:34:39.299 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 706.498ms
06-24 18:34:39.383 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 45.575ms
06-24 18:34:39.407 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 17.370ms
06-24 18:34:39.699 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 69.589ms
06-24 18:34:39.746 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 994(15KB) AllocSpace objects, 0(0B) LOS objects, 15% free, 21MB/25MB, paused 239.301ms total 1.413s
06-24 18:34:41.051 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 453.236ms
06-24 18:34:41.115 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 13.914ms
06-24 18:34:41.142 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 16.221ms
06-24 18:34:41.382 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 7876(123KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 25MB/25MB, paused 220.215ms total 1.145s
06-24 18:34:42.597 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 997.392ms
06-24 18:34:42.684 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 35.773ms
06-24 18:34:42.712 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 23.099ms
06-24 18:34:42.963 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 44.938ms
06-24 18:34:42.996 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 648(10KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 25MB/29MB, paused 229.056ms total 1.552s
06-24 18:34:44.302 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 686.164ms
06-24 18:34:44.618 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 19.549ms
06-24 18:34:44.657 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6491(101KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 29MB/29MB, paused 242.421ms total 1.111s
06-24 18:34:44.697 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 5.579ms
06-24 18:34:46.091 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 982.963ms
06-24 18:34:46.187 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 48.409ms
06-24 18:34:46.217 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 30.455ms
06-24 18:34:46.521 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 53.534ms
06-24 18:34:46.557 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 493(8KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 29MB/33MB, paused 279.881ms total 1.793s
06-24 18:34:46.558 2533-2546/adnan.com.ufone I/art﹕ WaitForGcToComplete blocked for 177.448ms for cause HeapTrim
06-24 18:34:46.565 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 7.621ms
06-24 18:34:46.617 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 5.539ms
06-24 18:34:48.156 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 527.372ms
06-24 18:34:48.227 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 19.215ms
06-24 18:34:48.262 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 23.554ms
06-24 18:34:48.573 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 7983(124KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 34MB/34MB, paused 299.130ms total 1.363s
06-24 18:34:50.275 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 1.148s
06-24 18:34:50.383 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 55.210ms
06-24 18:34:50.420 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 30.946ms
06-24 18:34:50.987 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 55.924ms
06-24 18:34:51.027 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 736(11KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 34MB/38MB, paused 540.864ms total 2.293s
06-24 18:34:52.411 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 788.050ms
06-24 18:34:52.967 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 18.129ms
06-24 18:34:53.016 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6533(102KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 38MB/38MB, paused 460.383ms total 1.518s
06-24 18:34:53.022 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 5.227ms
06-24 18:34:54.877 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 1.750s
06-24 18:34:54.994 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 56.245ms
06-24 18:34:55.034 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 34.575ms
06-24 18:34:55.600 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 60.212ms
06-24 18:34:55.646 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 523(8KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 39MB/43MB, paused 540.285ms total 2.500s
06-24 18:34:55.707 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 9.558ms
06-24 18:34:57.529 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 882.265ms
06-24 18:34:57.916 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 13.107ms
06-24 18:34:57.967 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6570(102KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 42MB/43MB, paused 330.003ms total 1.484s
06-24 18:34:58.076 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 18.763ms
06-24 18:34:58.166 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 7.498ms
06-24 18:35:00.368 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 1.725s
06-24 18:35:00.509 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 80.845ms
06-24 18:35:00.554 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 34.853ms
06-24 18:35:01.107 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 129.755ms
06-24 18:35:01.207 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 396(6KB) AllocSpace objects, 0(0B) LOS objects, 8% free, 43MB/47MB, paused 457.546ms total 2.876s
06-24 18:35:01.213 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 6.128ms
06-24 18:35:01.268 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 5.916ms
06-24 18:35:02.922 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 771.276ms
06-24 18:35:03.348 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 13.384ms
06-24 18:35:03.427 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6529(102KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 46MB/47MB, paused 362.529ms total 1.599s
06-24 18:35:03.436 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 9.090ms
06-24 18:35:05.916 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 2.370s
06-24 18:35:06.058 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 69.562ms
06-24 18:35:06.104 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 35.235ms
06-24 18:35:06.626 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 118.373ms
06-24 18:35:06.717 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 403(6KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 47MB/51MB, paused 437.964ms total 3.091s
06-24 18:35:06.727 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 9.203ms
06-24 18:35:06.817 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 12.111ms
06-24 18:35:08.997 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 1.331s
06-24 18:35:09.487 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 21.644ms
06-24 18:35:09.586 2533-2547/adnan.com.ufone I/art﹕ Background sticky concurrent mark sweep GC freed 6093(95KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 50MB/51MB, paused 413.239ms total 2.087s
06-24 18:35:09.588 2533-2546/adnan.com.ufone I/art﹕ WaitForGcToComplete blocked for 1.165s for cause HeapTrim
06-24 18:35:09.608 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 21.341ms
06-24 18:35:09.719 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 16.034ms
06-24 18:35:12.316 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 2.375s
06-24 18:35:12.541 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 133.257ms
06-24 18:35:12.625 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 77.153ms
06-24 18:35:13.123 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 73.703ms
06-24 18:35:13.196 2533-2547/adnan.com.ufone I/art﹕ Background partial concurrent mark sweep GC freed 396(6KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 500.092ms total 3.198s
06-24 18:35:13.206 2533-2547/adnan.com.ufone W/art﹕ Suspending all threads took: 9.346ms
06-24 18:35:13.316 2533-2540/adnan.com.ufone W/art﹕ Suspending all threads took: 17.881ms
06-24 18:35:13.934 2533-2539/adnan.com.ufone I/art﹕ Thread[2,tid=2539,WaitingInMainSignalCatcherLoop,Thread*=0xb4827800,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
06-24 18:35:13.935 2533-2539/adnan.com.ufone I/art﹕ Mutator lock exclusive owner tid: 2540
06-24 18:35:13.935 2533-2539/adnan.com.ufone I/art﹕ ThreadList lock owner tid: 2540
06-24 18:35:13.935 2533-2539/adnan.com.ufone I/art﹕ ClassLinker classes lock owner tid: 0
06-24 18:35:13.935 2533-2539/adnan.com.ufone I/art﹕ ClassLinker dex lock owner tid: 0
06-24 18:35:13.935 2533-2539/adnan.com.ufone I/art﹕ [ 06-24 18:35:13.971 2533: 2539 W/art ]
Suspending all threads took: 35.743ms
答案 0 :(得分:1)
您也可以像这样实现BASE类
public class PrepaidBase extends Activity {
AlertDialog.Builder builder;
private String number = "";
private String packageName;
private String price;
private String title;
public PrepaidBase()
{}
public void setPackageInformation(String name, String price, String number, String title)
{
this.number = number;
this.packageName = name;
this.price = price;
this.title = title;
}
public void activatePackage()
{
try
{
new AlertDialog.Builder(PrepaidBase.this)
.setTitle(PrepaidBase.this.title)
.setMessage("Are you sure you want to activate " + PrepaidBase.this.packageName + " in RS: " + PrepaidBase.this.price)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent in = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode(PrepaidBase.this.number)));
startActivity(in);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
//.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}catch (ActivityNotFoundException e)
{
e.printStackTrace();
}
}
和你从BASE继承的其他CHILD类</ p>
public class PrepaidLBO extends PrepaidBase implements View.OnClickListener {
Button chobeesButton;
public PrepaidLBO()
{
setPackageInformation("Package Name", "Your Price", "*123#", "Your Title");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chobeesghantay);
chobeesButton = (Button) findViewById(R.id.chobeesButton);
chobeesButton.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
activatePackage();
}
答案 1 :(得分:0)
您正在递归创建大量实例
你的问题是这行 PrepaidBase pb = new PrepaidBase(); ,它位于 PrepaidBase 活动内。
这意味着每次创建PrepaidBase实例时,它都会创建自己的另一个实例,直到达到内存限制,并且GC启动。