android无法实例化服务,Android:无法实例化类:没有空的构造函数

请看下面,我得到一个无法实例化类:当试图运行我的“HomeFragmentListExpand”类时,LogCat中没有空的构造函数错误,即使我清楚地有一个空的构造函数那里。Android:无法实例化类:没有空的构造函数

import android.app.Fragment;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.app.Activity;

import android.content.Intent;

import android.util.SparseArray;

import android.widget.ExpandableListView;

public class HomeFragment extends Fragment {

public HomeFragment(){}

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.fragment_home, container, false);

Intent intent = new Intent(getActivity(), HomeFragmentListExpand.class);

startActivity(intent);

return rootView;

}

public class HomeFragmentListExpand extends Activity {

public HomeFragmentListExpand(){

super();

}

// more efficient than HashMap for mapping integers to objects

SparseArray groups = new SparseArray();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.fragment_home);

createData();

ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);

MyExpandableListAdapter adapter = new MyExpandableListAdapter(this,

groups);

listView.setAdapter(adapter);

}

public void createData() {

for (int j = 0; j < 5; j++) {

Group group = new Group("Test " + j);

for (int i = 0; i < 5; i++) {

group.children.add("Sub Item" + i);

}

groups.append(j, group);

}

}

}

}

logcat的.........

01-10 16:41:45.143: E/AndroidRuntime(24809): FATAL EXCEPTION: main

01-10 16:41:45.143: E/AndroidRuntime(24809): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.smarte.smarteproducts/com.smarte.smarteproducts.HomeFragment$HomeFragmentListExpand}: java.lang.InstantiationException: can't instantiate class com.smarte.smarteproducts.HomeFragment$HomeFragmentListExpand; no empty constructor

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2435)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2574)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.app.ActivityThread.access$600(ActivityThread.java:162)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1413)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.os.Handler.dispatchMessage(Handler.java:99)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.os.Looper.loop(Looper.java:158)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.app.ActivityThread.main(ActivityThread.java:5789)

01-10 16:41:45.143: E/AndroidRuntime(24809): at java.lang.reflect.Method.invokeNative(Native Method)

01-10 16:41:45.143: E/AndroidRuntime(24809): at java.lang.reflect.Method.invoke(Method.java:525)

01-10 16:41:45.143: E/AndroidRuntime(24809): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)

01-10 16:41:45.143: E/AndroidRuntime(24809): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)

01-10 16:41:45.143: E/AndroidRuntime(24809): at dalvik.system.NativeStart.main(Native Method)

01-10 16:41:45.143: E/AndroidRuntime(24809): Caused by: java.lang.InstantiationException: can't instantiate class com.smarte.smarteproducts.HomeFragment$HomeFragmentListExpand; no empty constructor

01-10 16:41:45.143: E/AndroidRuntime(24809): at java.lang.Class.newInstanceImpl(Native Method)

01-10 16:41:45.143: E/AndroidRuntime(24809): at java.lang.Class.newInstance(Class.java:1130)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)

01-10 16:41:45.143: E/AndroidRuntime(24809): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)

01-10 16:41:45.143: E/AndroidRuntime(24809): ... 11 more

01-10 16:46:46.023: D/Process(24809): killProcess, pid=24809

01-10 16:46:46.023: D/Process(24809): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:123 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690

Android清单....

package="com.smarte.smarteproducts"

android:versionCode="1"

android:versionName="1.0" >

android:minSdkVersion="14"

android:targetSdkVersion="19" />

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/Theme.Smartestyle" >

android:name="com.smarte.smarteproducts.MainActivity"

android:label="@string/app_name" >

+0

你称之为片段,但它扩展了活动? –

+0

你有一个活动类作为片段的内部类?张贴您的清单。我猜你很困惑 –

+0

是的,因为我无法将活动类的内容放入片段类中。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值