开始新的缩进,但有错误

时间:2011-11-01 14:02:51

标签: java android

我有ExpandedList,我想在点击孩子时开始新的意图。但点击后程序崩溃。 在我看来,我使用标准代码来运行缩进。 我做错了什么? 这是我的代码:

package com.test;

import android.app.ExpandableListActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.TextView;

public class OWActivity extends ExpandableListActivity {

    ExpandableListAdapter mAdapter;
    public String[] groups;
    public String[][] children;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {

            Resources res = getResources();
            groups = res.getStringArray(R.array.books_array);

            String[] children_tmp = res.getStringArray(R.array.pray_array);
            children = new String[children_tmp.length][];
            for (int i = 0; i < children_tmp.length; i++) {
                String[] separated = children_tmp[i].split(";");
                children[i] = new String[separated.length];
                for (int j = 0; j < separated.length; j++) {
                    children[i][j] = separated[j].trim();
                }
            }
        } catch (Exception e) {
            System.out.println("Errrr +++ " + e.getMessage());
        }
        // Set up our adapter
        mAdapter = new MyExpandableListAdapter();
        setListAdapter(mAdapter);
        registerForContextMenu(getExpandableListView());
    }

    public class MyExpandableListAdapter extends BaseExpandableListAdapter {
        // Sample data set. children[i] contains the children (String[]) for
        // groups[i].

        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            return children[groupPosition].length;
        }

        public TextView getGenericView() {
            // Layout parameters for the ExpandableListView
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT, 64);

            TextView textView = new TextView(OWActivity.this);
            textView.setLayoutParams(lp);
            // Center the text vertically
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            // Set the text starting position
            textView.setPadding(36, 0, 0, 0);
            return textView;
        }

        public View getChildView(int groupPosition, int childPosition,
                boolean isLastChild, View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getChild(groupPosition, childPosition).toString());

            textView.setOnClickListener(new View.OnClickListener() {

                public void onClick(View view) {

// !!!!!!!!!!!!!!!!!!!!!!!!!!
// after this line - crash !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!
                    Intent myIntent = new Intent(view.getContext(), ViewText.class);
                    startActivityForResult(myIntent, 0);
                }
            });
            return textView;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getGroup(groupPosition).toString());
            return textView;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }

    }

}

带缩进的类我想运行。我想将一些文本加载到webview:

package com.test;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class ViewText extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_text);

        WebView myWebView = (WebView) findViewById(R.id.webview);
        myWebView.loadUrl("file:///android_asset/test.html");


        };
}

ViewText.xml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </WebView>

</LinearLayout>

1 个答案:

答案 0 :(得分:1)

我猜你正在调用的活动没有添加到AndroidManifest.xml文件中。

如果添加Logcat输出,我们可以提供更精确的答案。