· 8 years ago · Mar 08, 2018, 11:18 PM
1I am getting following error in my database
2
3public static final String DATABASE_FILE_NAME = "article.db";
4// @formatter:off
5public static final String SQL_CREATE_TABLE_ARTICLE = "CREATE TABLE IF NOT EXISTS "
6 + ArticleColumns.TABLE_NAME + " ( "
7 + ArticleColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
8 + ArticleColumns.TITLE + " TEXT NOT NULL, "
9 + ArticleColumns.TITLE_DESCRIPTION + " TEXT, "
10 + ArticleColumns.AUTHOR + " TEXT, "+
11 " );";
12
13public class NewsDetailActivity extends AppCompatActivity {
14 ImageButton addToFavoritesBtn;
15 Article article;
16 @Override
17 protected void onCreate(Bundle savedInstanceState) {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.news_details);
20
21
22 Toolbar myChildToolbar =
23 (Toolbar) findViewById(R.id.detail_toolbar);
24 setSupportActionBar(myChildToolbar);
25
26 // Get a support ActionBar corresponding to this toolbar
27 ActionBar ab = getSupportActionBar();
28 ab.setDisplayHomeAsUpEnabled(true);
29
30 // Enable the Up button
31
32 getSupportActionBar().setDisplayShowTitleEnabled(false);
33
34 final Article article = (Article) getIntent().getParcelableExtra("myDataKey");
35
36 FloatingActionButton share = (FloatingActionButton)findViewById(R.id.share_fab);
37 ImageButton shareButton = (ImageButton)findViewById(R.id.share_button);
38 shareButton.setOnClickListener(new View.OnClickListener() {
39 @Override
40 public void onClick(View v) {
41 Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
42 sharingIntent.setType("text/plain");
43 String articleDescription = article.getDescription() ;
44 String articleTitle = article.getTitle();
45 sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, articleDescription);
46 sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, articleTitle);
47 startActivity(Intent.createChooser(sharingIntent, "Share using"));
48 }
49 });
50
51 share.setOnClickListener(new View.OnClickListener() {
52 @Override
53 public void onClick(View v) {
54
55 Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
56 sharingIntent.setType("text/plain");
57 String articleDescription = article.getDescription() ;
58 String articleTitle = article.getTitle();
59 sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, articleDescription);
60 sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, articleTitle);
61 startActivity(Intent.createChooser(sharingIntent, "Share using"));
62 }
63 });
64 TextView textView = (TextView) findViewById(R.id.article_title);
65 final String articleTitle = article.getTitle();
66
67 if (articleTitle != null) {
68 textView.setText(articleTitle);
69 }
70 TextView textView1 = (TextView) findViewById(R.id.article_author);
71 final String articleAuthor = article.getAuthor();
72
73
74 if (articleAuthor != null) {
75 textView1.setText(articleAuthor);
76 }
77
78
79 TextView textView2 = (TextView) findViewById(R.id.article_body);
80 String articleDescription = article.getDescription();
81 if (articleDescription != null) {
82 textView2.setText(articleDescription);
83
84 }
85 Button button = (Button) findViewById(R.id.article_url);
86 final String articleUrl = article.getUrl();
87
88
89 button.setOnClickListener(new View.OnClickListener() {
90 @Override
91 public void onClick(View arg0) {
92 Intent intent = new Intent(Intent.ACTION_VIEW,
93 Uri.parse(articleUrl));
94 startActivity(intent);
95 }
96 });
97
98 Picasso.with(this).load(article.getUrlToImage()).into((ImageView) findViewById(R.id.photo));
99
100 addToFavoritesBtn = (ImageButton) findViewById(R.id.favorite_button);
101 addToFavoritesBtn.setOnClickListener(new View.OnClickListener() {
102 @Override
103 public void onClick(View view) {
104 ContentValues values = new ContentValues();
105 values.put(ArticleColumns._ID, "INTEGER PRIMARY KEY AUTOINCREMENT"); //Value bro example 1
106 values.put(ArticleColumns.TITLE, article.getTitle() ); // name
107 values.put(ArticleColumns.TITLE_DESCRIPTION, article.getDescription());
108 values.put(ArticleColumns.AUTHOR, article.getAuthor());
109
110 getContentResolver().insert(ArticleColumns.CONTENT_URI, values);
111 }
112 });
113 }
114 // String articlePublisheAt = article.getPublishedAt();
115 // TextView textView3 = (TextView) findViewById(R.id.textPublisher);
116 // if (articlePublisheAt != null) {
117 // textView3.setText(articlePublisheAt);
118 //<TextView
119 // android:id="@+id/textPublisher"
120 // style="?android:attr/textAppearanceLarge"
121 // android:layout_width="match_parent"
122 // android:layout_height="wrap_content"
123 // android:textColor="#fff"
124 //android:textStyle="bold"
125 //android:textSize="20sp"
126 //android:lineSpacingMultiplier="0.9"/>
127
128 //}
129
130
131}