This is my main activity
public class MainActivity extends AppCompatActivity {
//private static Button buttonPst;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent I = new Intent();
I.setAction("android.amila.action.PST");
startActivity(I);
}
}
);
}
}
Custom_row
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
android:text="@string/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rowTitle"
android:layout_weight="1"
android:textSize="18sp"
android:typeface="normal" />
android:text="@string/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rowSubtitle"
android:layout_weight="1"
android:textSize="18sp" />
and this is xml file
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_pst"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.amila.newglossary.pst"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:id="@+id/pstList" />
.java file
public class pst extends Activity {
String[] englishName = new String[]{"bacon", "Ham", "Tuna", "Candy", "Meatball", "Potato"};
String[] sinhalaName = new String[]{"wdddbhha", "wdddbhha", "wdddbhha", "wdddbhha", "wa", "wa"};
// Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_pst);
ListView listView = (ListView) findViewById(R.id.pstList);
adapter ada= new adapter(this,englishName,sinhalaName);
listView.setAdapter(ada);
}
}
this is adapter class
public class adapter extends ArrayAdapter {
String[] englishName;
String[] sinhalaName;
Context c;
LayoutInflater inflater;
public adapter(Context context, String[] englishName,String[] sinhalaName) {
super(context, R.layout.custom_row,englishName);
this.c=context;
this.englishName=englishName;
this.sinhalaName=sinhalaName;
}
public class ViewHolder{
TextView englishTv;
TextView sinhalaTv;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
inflater = (LayoutInflater)
c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.custom_row, null);
}
final ViewHolder holder=new ViewHolder();
holder.englishTv=(TextView)convertView.findViewById(R.id.rowTitle);
holder.sinhalaTv=(TextView)convertView.findViewById(R.id.rowSubtitle);
holder.englishTv.setText(englishName[position]);
holder.sinhalaTv.setText(sinhalaName[position]);
return super.getView(position, convertView, parent);
}
}
I have tried this very much and the first window(main activity) is running without errors when pressing the PST,the window with the list view not appears. this error appears in RUN and closes the app
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.amila.newglossary, PID: 6309
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.amila.newglossary/com.example.amila.newglossary.pst}:
java.lang.RuntimeException: Your content must have a ListView whose id
attribute is 'android.R.id.list'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.ListActivity.onContentChanged(ListActivity.java:243)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:419)
at android.app.Activity.setContentView(Activity.java:2414)
at com.example.amila.newglossary.pst.onCreate(pst.java:42)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
No comments:
Post a Comment